0

I am creating a CSV file with UTF-8 encoding.

It displays the Chinese characters properly if I open it using Notepad++.

It displays the Chinese characters properly if I open it using Notepad.

But, if I open it using Excel, I see garbage values.

If I open it using Notepad and press Control+S and close the file and reopen in Excel, it shows the characters perfectly.

Any clues whats going here?

I also tried to create a normal CSV file which has Encoding GB2312. I then used Unix command iconv to convert the file from "GB2312" to "UTF-8"

This command removes all the Chinese characters and shows only English characters. So, this is not a solution.

Please suggest.

Edit -

It doesn't show Garbage value, but shows ANSI encoding. Why does it picks ANSI encoding by default. And why after opening the same file in Notepad/Notepad++ it opens up with UTF-8.

Also, why just Control+s makes it open in Excel correctly.

Techidiot
  • 1,921
  • 1
  • 15
  • 28
  • I think this question belongs to [Super User](http://superuser.com/). – lingo Aug 12 '15 at 21:04
  • possible duplicate of [How can I output a UTF-8 CSV in PHP that Excel will read properly?](http://stackoverflow.com/questions/4348802/how-can-i-output-a-utf-8-csv-in-php-that-excel-will-read-properly) – deceze Aug 13 '15 at 08:34
  • Yeah, I created duplicate as the moderator suggested. In case if required, any moderator can remove it. – Techidiot Aug 13 '15 at 11:45

1 Answers1

0

I was aware of BOM sequence with UTF-8 encoding but was not aware of how to add it in my file.

Now, the BOM sequence is 0xEF,0xBB,0xBF, so I tried add this as plain text but it didn't worked. So, I added the ASCII values of these to my CSV and it works.

ASCII value is =

new.text = chr$(239) & chr$(187) & chr$(191) |Concatenated

Simply add this as 1st line and it works!

Techidiot
  • 1,921
  • 1
  • 15
  • 28
  • 1
    Not for all versions of Excel though... To put it bluntly: Excel notoriously sucks with encodings. – deceze Aug 13 '15 at 08:34