Sijith
Sijith

Reputation: 3930

CSV file having chinese content shows unknown characters

My project generates report in CSV format based on selected language. We supports 17 languages in that Asian languages like Chinese/Japanese and Korean not working. Contents inside shows some unknow character but on opening same in Notepad++ and excel by choosing unicode "65001: Unicode (UTF-8)" its showing Chinese character properly.

In code we set some flags while generating CSV

std::ofstream* outFile = new std::ofstream(qPrintable(filePath),std::ios::app);
CSVostream csv( outFile );
csv.setf(std::ios::fixed, std::ios::floatfield);

Do we need to set some other flag or what I am missing I am not sure. Can some one provide some light on this.

Upvotes: 0

Views: 85

Answers (1)

Friedrich
Friedrich

Reputation: 4817

The problem is not in how the file is written but how it is read.

CSV files are text files and they carry no meta-information on how they are encoded. So it's up the user to guess. In your case, Notepad++ seems to be better at guessing than Excel.

A similar problem was asked in Is it possible to force Excel recognize UTF-8 CSV files automatically?

Some answers mention adding a BOM to the CSV which is recognized by some versions of Excel.

Some more related questions:

Opening CSV with UTF-8 BOM via Excel

Should UTF-8 CSV files contain a BOM byte order mark (on SE SE)

Upvotes: 0

Related Questions