【问题标题】:CSV file export with encoding issuesCSV 文件导出存在编码问题
【发布时间】:2017-01-22 19:55:28
【问题描述】:

标签: c# sql-server csv encoding utf-8


【解决方案1】:

为了正确解码 HTML 文件,您的浏览器需要知道使用哪种编码。你可以通过设置charset parameter或者设置meta tag告诉他:<meta charset="UTF-8">

所以:您需要使用 UTF-8 保存 HTML 文件并正确声明该编码。

理论上,您的服务器上的默认编码也可能不是 UTF-8 - 那么您应该从 .htaccess 服务器文件中删除 AddDefaultCharset your_encoding 并写入 AddDefaultCharset utf-8。但我不确定这是否与您的情况有关。

编辑:

字节ó 代表UTF-8 中的西班牙字符ó。所以我认为你不应该尝试用其他编码进行编码,因为它绝对是utf-8。

【讨论】:

  • 带有 C#/ASP.NET 的 CMS 不支持 .htaccess 配置
  • 好的,很高兴知道。如果您的问题没有解决,我会为您提供更新,您可以尝试其他方法
【解决方案2】:

你可以试试下面的代码

        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8) + "");
        Response.Cookies.Add(new System.Web.HttpCookie("fileDownload", "true"));
        Response.Charset = "";
        Response.ContentType = "application/csv";
        Response.ContentEncoding = Encoding.UTF8;
        Response.BinaryWrite(Encoding.UTF8.GetPreamble());
        Response.Write(outPutStringData); // Information which you want in .csv file
        Response.Flush();
        Response.End();

【讨论】:

    猜你喜欢
    • 2019-08-10
    • 2015-11-04
    • 2017-07-16
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    相关资源
    最近更新 更多