0

I'm writing a CSV file which contains text with british pound and euro symbols, however when I opened the file in Excel, I see some rather odd behavior. I see some weird A-looking symbol before the british pound, and quotes instead of the euro symbol. I figured it's probably because Excel doesn't like a file that's UTF8 encoded.

fs.writeFileAsync("the-file.csv", text-containing-foreing-currency, "utf8");

Does anyone know a way to get around this while creating the file? I don't want the users to have to do anything with excel after downloading the file, I just want them to be able to open the file and see the right symbols.

  • It sounds like you are double-clicking the CSV from an Explorer window to open it (by default file association) in Excel. Use VBA's [Workbooks.OpenText method](https://msdn.microsoft.com/en-us/library/office/ff837097.aspx), open Excel to a blank workbook and use Data Get External Data ► From Text and specify the code page with File Origin on the first page of the wizard or use File, Open, Text Files and specify the code page with File Origin. –  Jul 08 '16 at 01:35
  • can you show a screenshot of the problem? – Lakshya Goyal Jul 08 '16 at 07:25

1 Answers1

0

There shouldn't be any problem with node writing the symbols to the file, if you open it with a text editor you should see the correct characters.

The problem is with excel opening UTF8 csv files. By default it assumes ANSI encoding, so if the file is in UTF8, it scrambles the characters. You can open the file correctly with the text import wizard. In general this is a limitation of excel. The best workaround for you will depend on your OS and Excel version. This is a heavily discussed topic, here are some good reads:

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

Which encoding opens CSV files correctly with Excel on both Mac and Windows?

Community
  • 1
  • 1
marton
  • 1,194
  • 6
  • 16