CSV file having chinese content shows unknown characters

57 views Asked by At

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.

1

There are 1 answers

0
Friedrich On

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)