首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导出excel后显示Mojibake字符

导出excel后显示Mojibake字符
EN

Stack Overflow用户
提问于 2012-07-26 11:48:20
回答 2查看 738关注 0票数 0

我不确定是否有人遇到过这个问题。以下是复制该问题的步骤。

步骤: 1.进入列表-->联系人页面。2.单击“导出”按钮,为联系人列表生成.XLS报告。3.关闭.XLS报表并定位至其他页面,例如联系人列表。4.在联系人列表中,点击[关闭]按钮,跳转回联系人列表页面。

预期:-页面应显示联系人列表页面。

实际:-显示一个包含mojibaki字符的奇怪页面。请参阅此url http://i.imgur.com/dIsZc.png中的图像

以下是使用活动报表生成excel的代码:

私有静态空PushContentToHttp(ActiveReport report,MemoryStream msData,string fileName,string fileName){

代码语言:javascript
复制
        report.Run();
        XlsExport xls = new XlsExport();
        xls.DisplayGridLines = true;
        xls.AutoRowHeight = true;
        xls.Export(report.Document, msData);

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.Buffer = true;

        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.AddHeader("Content-Length", msData.Length.ToString());
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename= \"" + fileName + ".xls\"");
        HttpContext.Current.Response.AddHeader("Refresh", "3; url=" + url);
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252);
        //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
        HttpContext.Current.Response.BinaryWrite(msData.ToArray());
        HttpContext.Current.Response.End();
 //       HttpContext.Current.Response.Redirect(url,true);

    }

任何帮助都将不胜感激!非常感谢!:)

EN

回答 2

Stack Overflow用户

发布于 2012-07-26 12:49:07

我敢打赌,这是因为Excel的默认编码是ANSI 125x,而您正试图将其写入UTF-8。

查看相关的SO问题:Character encoding in Excel spreadsheet (and what Java charset to use to decode it)

票数 0
EN

Stack Overflow用户

发布于 2012-07-27 09:48:10

实际上,导致这种情况的原因是您的页面试图重定向回浏览器缓存的Excel页面。我建议你做一个完整的重定向,而不是只做一个浏览器返回,这样前一个页面就会完全加载,而不是加载缓存的Excel页面。与ANSI编码无关,只是不正确的重定向问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11662076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档