0

我有一个网格视图,我将网格视图数据导出到 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();
        }
    }
4

1 回答 1

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();
于 2015-05-17T11:50:22.517 回答