gridview导出数据至Excel office2007、2010打开乱码_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > gridview导出数据至Excel office2007、2010打开乱码

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

 2010/12/12 15:05:16  wangwang3ok  http://wangwang3ok.javaeye.com  我要评论(0)
  • 摘要:原来代码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
  • 标签:2010 excel view 数据 Office

原来代码

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

?

发表评论
用户名: 匿名