我有一个网格视图,我将网格视图数据导出为单词,如下所示。网格视图数据和样式按预期工作。现在我想和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();
}
}
答案 0 :(得分:0)
我找到了。
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();