导出Excel中文出现乱码?

奔跑吧公牛 2008-12-04 02:24:03
一个很棘手得问题,导出Excel时中文出现乱码,而且是数据量达到一定上限的时候,
数据也不多,600行30列、
当在25列的时候还是正常的,再多就不行了,行数没有限制
哪位大侠帮帮忙?
网上提到的方法都试过了,不行。


版本一
...
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8)+".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
...

版本二
...
Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
...

版本三
...
Response.ContentEncoding = System.Text.Encoding.UTF7;
...
...全文
968 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
laoyingisme 2008-12-05
  • 打赏
  • 举报
回复
修改web.config中的 utf8 改为gb2312
qqhahazxxqq 2008-12-05
  • 打赏
  • 举报
回复

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)));
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
clarke563 2008-12-05
  • 打赏
  • 举报
回复
我试过加上这几句不会出现乱码情况
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
但是当我发布后,Excel里却没有数据.各位,请指教一下....
mengxj85 2008-12-04
  • 打赏
  • 举报
回复
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.GridView1.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
奔跑吧公牛 2008-12-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Zeteyu 的回复:]
试下
Response.ContentType = "application/vnd.ms-excel;charset=UTF-8";
[/Quote]
楼上说的不行啊
Zeteyu 2008-12-04
  • 打赏
  • 举报
回复
试下
Response.ContentType = "application/vnd.ms-excel;charset=UTF-8";
wuyq11 2008-12-04
  • 打赏
  • 举报
回复
看看是否是配置问题
popfei3707 2008-12-04
  • 打赏
  • 举报
回复
UP UP,抬起头
奔跑吧公牛 2008-12-04
  • 打赏
  • 举报
回复
怎么没有人啊,Up一下

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧