0

私はグリッドビューを持っており、以下に示すように、グリッドビューのデータを単語にエクスポートしました。グリッド ビューのデータとスタイルは、期待どおりに機能します。今、私はワード文書に新しいヘッダー行を追加し、その下にグリッドビューデータを送信したいと考えています。Response.Output.Write(sw.ToString()); の前に単語文書に見出しを追加する必要があります。ライン。助けてください。

敬具、

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