导出csv文件时韩文乱码解决方法

时间:2023-01-06 13:16:49

从asp.net导出csv这样配置可以防止韩文等乱码,在头部加上0xEF, 0xBB, 0xBF:

string fileName = "attachment;filename=" + HttpUtility.UrlEncode("文档");
Response.AppendHeader(
"Content-Disposition", httpHeader);
Response.ContentType
= "text/csv";
Response.Charset
= "UTF-8";
Response.ContentEncoding
= System.Text.Encoding.UTF8;
Response.HeaderEncoding
= System.Text.Encoding.UTF8;
Response.BinaryWrite(
new byte[] { 0xEF, 0xBB, 0xBF }); //Important!
Response.Write(sw);
Response.Flush();
Response.Close();

-