Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileNamel.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//設定輸出流為簡體中文
Response.ContentType = "application/ms-excel";//設定輸出檔案類型為excel檔案。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
以上代碼copy來用就可以實作了
本文轉自 wenyan 51CTO部落格,原文連結:http://blog.51cto.com/wenyan/10138