- void ExportExcel( System.Web.UI.WebControls.DataList dl, string strFileName)
- {
- strFileName = System.Web.HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8);
- System.Web.HttpContext.Current.Response.Clear();
- System.Web.HttpContext.Current.Response.Buffer = true;
- System.Web.HttpContext.Current.Response.Charset = "gb2312";
- System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "online; filename=" + strFileName + ".xls");
- System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
- System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
- 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);
- dl.RenderControl(oHtmlTextWriter);
- System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString().Replace("<td", "<td STYLE='MSO-NUMBER-FORMAT://@'"));
- System.Web.HttpContext.Current.Response.Buffer = false;
- System.Web.HttpContext.Current.Response.End();
- }
datalist导出excel
最新推荐文章于 2022-12-12 10:56:23 发布