0

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.

opensource-developer
  • 2,826
  • 4
  • 38
  • 88
  • You need to post an example of the CSV file content, as well as describe what "all messed up" actually means. Like, does it look like it was run through an encryption algorithm? Are the data placed into the wrong columns? Split up? What does "messed up" mean? – Lasse V. Karlsen Sep 08 '20 at 08:25
  • @LasseV.Karlsen thanks for your reply. I have updated the questions with few screenshots. hope it helps. – opensource-developer Sep 08 '20 at 08:38

0 Answers0