我有以下代码:
output = ...
(some comma-separated data)
Response.Clear
'Response.ChartSet = "UTF-8"
'Response.CodePage = 65001
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "filename=myfile.csv;"
Response.Write(output)
Response.End
现在,一切都工作正常,拥有数据本身并生成虚拟CSV文件以供直接下载,但如果我在一个或多个字段(列)中有非ascii数据,我不会得到它在UTF-8中生成的UTF-8。
如何将生成的文件的内容设置为UTF-8 ??
此代码中的每条注释行似乎都不会影响输出...
答案 0 :(得分:6)
如果您在Excel中打开CSV并想知道UTF-8
编码无效的原因,请继续我的评论,请不要担心这是Excel识别UTF-8
CSV数据的副作用
在编写输出之前尝试添加此内容
'BOM to dup Excel into encoding the CSV correctly instead of using ASCII!!!
Call Response.BinaryWrite(ChrB(239) & ChrB(187) & ChrB(191))
有用的链接