`
wangwang3ok
  • 浏览: 77070 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

gridview导出数据至Excel office2007、2010打开乱码

阅读更多

原来代码

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();

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics