ASP.NET DATAGRIDVIWE控件导出Execle
来源:互联网 发布:共享单车大数据 编辑:程序博客网 时间:2024/06/06 12:55
public void ExportExcel12(Control ctl, string fileName) { Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".xls"); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文 this.EnableViewState = false; Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">"); System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw); ctl.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); }