DataGrid导出到Word/Excel

        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.word";

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        DataGrid1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();

原文链接

https://www.codeproject.com/Articles/11056/Exporting-DataGrid-to-Excel-Word-and-Text-Files

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭