我有一个网格视图,我导出到网格视图数据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();
}
}
我找到了
HtmlTextWriter hw = new HtmlTextWriter(sw);
hw.Write("<div> <h3 align=center><span style=");
hw.Write(HtmlTextWriter.DoubleQuoteChar);
hw.Write("font-weight:bold; font-family:'Segoe UI'; color: #81040a;");
hw.Write(HtmlTextWriter.DoubleQuoteChar);
hw.Write(">LT Control</span> </h3></div>");
hw.WriteLine();