Is it possible to force Excel recognize UTF-8 CSV files automatically?

后端 未结 27 1686
醉梦人生
醉梦人生 2020-11-21 22:27

I\'m developing a part of an application that\'s responsible for exporting some data into CSV files. The application always uses UTF-8 because of its multilingual nature at

27条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 22:48

    This is an old question but I've just encountered had a similar problem and the solution may help others:

    Had the same issue where writing out CSV text data to a file, then opening the resulting .csv in Excel shifts all the text into a single column. After having a read of the above answers I tried the following, which seems to sort the problem out.

    Apply an encoding of UTF-8 when you create your StreamWriter. That's it.

    Example:

    using (StreamWriter output = new StreamWriter(outputFileName, false, Encoding.UTF8, 2 << 22)) {
       /* ... do stuff .... */
       output.Close();
    }
    

提交回复
热议问题