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