CSV encoding issues (Microsoft Excel)

后端 未结 3 609
一生所求
一生所求 2021-01-04 23:42

I am dynamically creating CSV files using C#, and I am encountering some strange encoding issues. I currently use the ASCII encoding, which works fine in Excel 2010, which I

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 00:28

    You need to add Preamble to file:

            var data = Encoding.UTF8.GetBytes(csv);
            var result = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
            return File(new MemoryStream(result), "application/octet-stream", "file.csv");
    

提交回复
热议问题