原来代码
- gvMonograph.DataBind();
- Response.Charset = "GB2312";
- Response.ContentEncoding = System.Text.Encoding.UTF7;
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
- Response.ContentType = FileType;
- this.EnableViewState = false;
- StringWriter tw = new StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(tw);
- gvMonograph.RenderControl(hw);
- Response.Write(tw.ToString());
- Response.End();
需要更改一个地方也就是Response.ContentEncoding = System.Text.Encoding.UTF7;
为Response.ContentEncoding = System.Text.Encoding.UTF8; 后即可在2007 2010下正常打开
改后代码:
- gvMonograph.DataBind();
- Response.Charset = "GB2312";
- Response.ContentEncoding = System.Text.Encoding.UTF8;
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
- Response.ContentType = FileType;
- this.EnableViewState = false;
- StringWriter tw = new StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(tw);
- gvMonograph.RenderControl(hw);
- Response.Write(tw.ToString());
- Response.End();
转自:http://wangwang3ok.iteye.com/blog/839594
本文介绍了一种解决使用ASP.NET中GridView导出数据到Excel时出现乱码的方法,通过调整编码设置使得在Office 2007及2010版本下能够正确显示中文。

3005

被折叠的 条评论
为什么被折叠?



