0

I use the json2csv module to convert the data I have to the csv extension and send it by mail, but all the data appears in the same column. What should I do to make it appear in separate columns

this is my json2csv.js

const {Parser} = require('json2csv')
module.exports.toCsv = function(list,header){
var arr =[];
  for (let i =0; i<header.length;i++){
    arr.push(header[i])
  }
    const field = arr;
    const opts = { field };
    try {
        const parser = new Parser(opts);
        const csv = parser.parse(list);
          console.log(csv);
     return csv
      } catch (err) {
        console.error(err);
      }
}

This is my sendMail.js

var mailOptions = {
  from: 'abc@gmail.com',
  to: 'abc@gmail.com',
  subject:param,
  text: 'Liste Ektedir',
  attachments: [{
    filename: param+'.csv',content:toCsv(groupsList,header)}
  ]
};

Csv file that i opened after sending mail enter image description here

This is I want

enter image description here

safa aytan
  • 431
  • 1
  • 6
  • 16
  • 1
    You need to open the CSV with a good program (i.e. not Excel) that allows you to set a comma as separator. (despite CSV standing for *comma*-separated vales, Excel expects semi-colons) –  Jun 08 '20 at 14:30
  • Thank you I convert to semi-colon from comma. it's was success – safa aytan Jun 09 '20 at 06:10

0 Answers0