0

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

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

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

实际: - 显示包含 mojibaki 字符的奇怪页面。请查看此网址中的图片http://i.imgur.com/dIsZc.png

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

私有静态无效 PushContentToHttp(ActiveReport 报告,MemoryStream msData,字符串文件名,字符串 url){

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

    }

任何帮助将不胜感激!太感谢了!:)

4

2 回答 2

0

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

请参阅这个相关的 SO 问题:Excel 电子表格中的字符编码(以及用于解码它的 Java 字符集)

于 2012-07-26T04:49:07.090 回答
0

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

于 2012-07-27T01:48:10.263 回答