双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

关于导出excel在谷歌浏览器中网络错误的问题

whilewk whilewk 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
具体代码如下

System.Web.UI.WebControls.GridView DGOutPut = new System.Web.UI.WebControls.GridView();
DGOutPut.Visible = true;
DGOutPut.RowDataBound += new GridViewRowEventHandler(DGOutPut_RowDataBound);
DGOutPut.DataSource = dt;
DGOutPut.DataBind();
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.Charset = "UTF-8";

System.Web.HttpContext.Current.Response.Charset = "GB2312";
System.Web.HttpContext.Current.Response.ContentEncoding = Encoding.Default;
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName + ".xls", System.Text.Encoding.UTF8));
//System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
//System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
DGOutPut.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);
DGOutPut.RenderControl(oHtmlTextWriter);
System.Web.HttpContext.Current.Response.Write(@"<style> .text {mso-number-format:\@; } </style> ");
System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString());
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
//System.Web.HttpContext.Current.Response.End();
//HttpContext.Current.ApplicationInstance.CompleteRequest();
DGOutPut.DataSource = null;
DGOutPut.Visible = false;
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
whilewk
C# 111,129 成员 642,540 内容