导出Excel

Response.Clear();
   Response.Buffer = true;
   Response.Charset = "gb2312";
   Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("中文名称") + ".xls");
   //Response.ContentEncoding = System.Text.Encoding.Default;

   Response.ContentType = "application/ms-excel";

   this.EnableViewState = false;

   System.IO.StringWriter oStringWriter = new StringWriter();
   System.Web.UI.HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);

   this.RenderControl(oHtmlTextWriter);
   Response.Write(oStringWriter.ToString());
   Response.End();

原文地址:https://www.cnblogs.com/RobotTech/p/661773.html