c# - 如何将英镑符号从 C# Web App 正确导出到 Excel? (生产£而不是£)

标签 c# .net excel character

我们正在将网站应用程序中的一些数据导出到 Excel 电子表格中,但是,当使用 GBP 符号时,不是输出“£9.99”而是生成“£9.99”。

这是一位同事编写的用于生成电子表格的代码 [tableOut 是一个包含 HTML 表格的 StringBuilder]:

string filename = "EngageReplies.xls";
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader( "content-disposition", "attachment;filename=" + filename );
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.EnableViewState = false;

Response.Write( tableOut );
Response.End();

关于如何获得所需输出的任何想法?

附注不确定我是否应该将其分成一个单独的问题,但是当生成电子表格时,会触发一条警告消息:

The file you are trying to open, 'EngageReplies.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

我使用 Firefox 和 IE 通过 Office 2007 打开文件。单击"is"可以打开文件,但如果我的用户不受此影响,我会更喜欢它。

最佳答案

啊哈!

首先我尝试删除 Charset 和 CharacterEncoding,但仍然得到错误的输出,所以我将它们设置为以下并且它工作正常:

Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;

感谢罗兰的灵感!

关于c# - 如何将英镑符号从 C# Web App 正确导出到 Excel? (生产£而不是£),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/772016/

相关文章:

arrays - 在 Excel 中使用 If 大语句并填充表格的剩余部分

c# - 如何获取组中项目的索引

c# - 使用有效获取数组参数的反射方法

c# - session 超时时如何在登录页面显示错误消息

.net - 使用 WCF 服务连接到 AppInitialize

.net - Entity Framework /MVC3 : temporarily disable validation

excel - 将数组中的单词匹配为字符串

c# - 处理关闭/断开网络套接字连接(CloseAsync 与 CloseOutputAsync)

.net - "Reverse-Resolution"带有 Ioc 容器?

string - 如果 ColA 中的一个单元格包含来自 ColC 列表的子字符串,那么该子字符串是否可以在 ColB 中返回?