简体   繁体   English

如何添加新的标题行asp.net Response.Output.Write?

[英]How to add new header line asp.net Response.Output.Write?

I have a grid-view and I exported to grid-view data to word as shown below. 我有一个网格视图,并将导出到网格视图的数据导出到word,如下所示。 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. 现在,我想将新的标题行添加到Word文档中,然后在其下发送我的网格视图数据。 I have to add heading to word document before Response.Output.Write(sw.ToString()); 我必须在Response.Output.Write(sw.ToString());之前的Word文档中添加标题。 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();
        }
    }

I found it. 我找到了。

            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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM