【问题标题】:Write µ to CSV file using c#使用 c# 将 µ 写入 CSV 文件
【发布时间】:2011-09-05 13:31:06
【问题描述】:

我正在使用以下代码写入 CSV 文件

HttpContext context = HttpContext.Current;
context.Response.Clear();                     
context.Response.Write("µm");                   
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=micron.csv");
context.Response.End();

但在 UI 中它显示为 µm 而不是 µm。我需要一点帮助。

【问题讨论】:

  • 文件的编码是什么?可能是 BOM 的错。
  • 哪个用户界面?您想对文件使用什么编码? UTF-8? (CSV 编码没有标准化...)

标签: c# asp.net utf-8 character-encoding c#-2.0


【解决方案1】:

看看HttpResponse下的ContentEncoding http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx 无论您在其中显示文件的任何 UI 都可能使用与那里设置的不同的 UI。

【讨论】:

    【解决方案2】:

    我认为您不能简单地检查文件以查看它是否包含字符“”。

    如果它确实替换它。

    if (string.Contains("Â"))
            {
                string= string.Replace("Â", "");
            }
    

    字符串只是文件的内容。

    这只是一个猜测,我不知道这是否可行。

    【讨论】:

      猜你喜欢
      • 2011-08-19
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 2013-09-16
      • 1970-01-01
      相关资源
      最近更新 更多