我有一个网格视图,我将网格视图数据导出到 word,如下所示。网格视图数据和样式按我的预期工作。现在我想将新的标题行添加到 word 文档中,然后将我的网格视图数据发送到它下面。我必须在 Response.Output.Write(sw.ToString()); 之前向 word 文档添加标题 线。请提供任何帮助。
亲切的问候,
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();
}
}