2

I generate an utf-8 encoded csv with node.js and then I open it on windows with a double click. Excel starts but some special chars (like Ä, Ö, Ü, ä, ö, ü ...) are not correctly displayed. I think this is due to the wrong encoding. I saved a new csv created with excel. And I see the encoding is windows-1252.

I googled a lot and tried a lot, but no solution.

I try using combinations of https://github.com/mathiasbynens/windows-1252 and https://github.com/kvz/phpjs/tree/master/functions/xml

data = helper.utf8_encode(data);
data = helper.utf8_decode(data);
data = windows1252.encode(data);
data = windows1252.decode(data);
data = helper.utf8_encode(windows1252.encode(data));
data = helper.utf8_encode(windows1252.decode(data));
data = helper.utf8_decode(windows1252.encode(data));
data = helper.utf8_decode(windows1252.decode(data));
data = windows1252.encode(helper.utf8_encode(data));
data = windows1252.decode(helper.utf8_encode(data));
data = windows1252.encode(helper.utf8_decode(data));
data = windows1252.decode(helper.utf8_decode(data));

But nothing works. Please help me

UPDATE: By tinkering I found out that these codes are displayed as the wished chars, but still missing lowercased äöü. Someone any idea?

\u0101 => Ä
\u010D => Ä
\u011D => Ä
\u0120 => Ä

\u0581 => Ö
\u058D => Ö
\u058F => Ö
\u0590 => Ö
\u059D => Ö
\u05A0 => Ö

\u0701 => Ü
\u070D => Ü
\u070F => Ü
\u0710 => Ü
\u071D => Ü
\u0720 => Ü

\u07C1 => ß
\u07CD => ß
\u07D0 => ß
\u07DD => ß
\u07E0 => ß
Dennis
  • 397
  • 1
  • 5
  • 16

1 Answers1

0

I'm not totally satisfied by that answer because I get a warning with the npm install iconv command. Still, it should solve your issue:

const Iconv = require('iconv').Iconv;
const fs = require('fs');
const iconv = new Iconv('utf8', 'utf16le');

let csvContent = 'ÉëÜè whatever you want';
fs.writeFileSync('test.csv', iconv.convert(csvContent));
herve
  • 3,825
  • 2
  • 18
  • 27
  • found issue of my warning: https://github.com/nodejs/node-gyp/issues/942 I'm satisfied now ☺️ – herve Aug 29 '17 at 18:20