如何正确地将英镑符号从C#Web应用程序导出到Excel?(£生成而不是£)

Ric*_*ich 2 .net c# 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();
Run Code Online (Sandbox Code Playgroud)

我们如何获得所需的输出?

ps不确定是否应将其分成单独的问题,但在生成电子表格时会触发警告消息:

您尝试打开的文件"EngageReplies.xls"的格式与文件扩展名指定的格式不同.在打开文件之前,请验证文件是否已损坏且是否来自受信任的源.你想现在打开文件吗?

我已经使用Firefox和IE用Office 2007打开文件.单击是打开文件可以,但如果我的用户没有受到它,我会更喜欢它.

Ric*_*ich 6

啊哈!

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

Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
Run Code Online (Sandbox Code Playgroud)

感谢Rowland的灵感!