我有关于丹麦语字符的问题,并在 Excel 中打开保存为 CSV 的文件。请参阅下面的代码:
\n\n [HttpGet]\n [Route("/progress/data.csv")]\n [Produces("text/csv")]\n public IActionResult GetCSV()\n {\n StringBuilder sb = new StringBuilder();\n sb.AppendLine("\xc3\xa6\xc3\xb8;2;3;");\n Encoding encode = Encoding.UTF8;\n return File(encode.GetBytes(sb.ToString()), "text/csv", "data.csv");\n }\nRun Code Online (Sandbox Code Playgroud)\n\n我使用的是 .NET Core 2.1,此导出的结果是前两个字符 \xc3\xa6\xc3\xb8 显示为 \xc3\x83\xc2\xa6\xc3\x83 。
\n\n我知道这是一个已知问题,但到目前为止我还没有找到解决方案。在过去的 4 个小时里,我尝试了至少 15 种不同的方法,包括带/不带 BOM 的 UTF。使用 System.Text.Encoding.UTF8.GetPreamble() 手动添加 BOM,各种 MemoryStream、StreamWriter 解决方案,尝试使用 windows-1252 和 CodePagesEncodingProvider.Instance.GetEncoding(1252) 但没有任何效果。当在 Excel 中打开此文件时,结果总是与预期不同。
\n\n有人对此有解决方案吗?
\n