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

后端 未结 27 1746
醉梦人生
醉梦人生 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 23:10

    I am generating csv files from a simple C# application and had the same problem. My solution was to ensure the file is written with UTF8 encoding, like so:

    // Use UTF8 encoding so that Excel is ok with accents and such.
    using (StreamWriter writer = new StreamWriter(path, false, Encoding.UTF8))
    {
        SaveCSV(writer);
    }
    

    I originally had the following code, with which accents look fine in Notepad++ but were getting mangled in Excel:

    using (StreamWriter writer = new StreamWriter(path))
    {
        SaveCSV(writer);
    }
    

    Your mileage may vary - I'm using .NET 4 and Excel from Office 365.

提交回复
热议问题