我们正在将网站应用程序中的一些数据导出到 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/