I have a grid-view and I exported to grid-view data to word as shown below. The grid-view data and style works as I expected. Now I want to and new header line to word document and than send my grid-view data under it. I have to add heading to word document before Response.Output.Write(sw.ToString()); line. Any help please.
Kind regards,
protected void ExportToExcel(object sender, EventArgs e)
{
string nowTarih = DateTime.Now.ToString("yyyy-MM-dd");
string excelNameExport = "attachment;filename=" + nowTarih + "_LT_Raporu.doc";
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", excelNameExport);
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
Response.ContentType = "application/vnd.ms-word";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
mygrid.AllowPaging = false;
this.gvBind();
if (mygrid.Rows.Count > 0)
{
mygrid.Height = new Unit(mygrid.RowStyle.Height.Value * mygrid.Rows.Count);
}
mygrid.DataBind();
mygrid.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
**Response.Output.Write(sw.ToString());**
Response.Flush();
Response.End();
}
}