Node.js: CSV displays correctly on mac os(numbers) but displays all messed up on windows(excel)

269 Views Asked by At

I am generating a few csv files, the generating works well but when i open the file in Excel it displays all messed up, however the same file opens well in mac(numbers)

below is the relevant part of the code i am using to generate the files. csv.encoding is utf16le and csv.delimiter is \t

        await pipelineAsync(
          fs.createReadStream(sheet.path),
          csv.parse({delimiter: config.get('csv.delimiter')}),
          csv.transform((input) => {
            if(rowCountGenerated == false) {
              colCount = input.length;
              rowCountGenerated = true;
            }
            rowCount++;
            return Object.assign({}, input);
          }),
          csv.stringify({eol: true, record_delimiter: os.EOL, header: false, delimiter: config.get('csv.delimiter')}),
          fs.createWriteStream(fpath, {encoding: config.get('csv.encoding')})
        );

Below is how the data looks in excel

enter image description here

Below is how the data looks in numbers

enter image description here

Any ideas?

UPDATE 1: looks like excel is ignoring the col separator, by manually editing the file and adding sep='\t' as the first row, i was able to fix the issue see the file correctly in excel too.

The only question I have now is how to change the above code to add sep=\t as the first row of my file.

Thanks.

0

There are 0 best solutions below