Closed ryanf12 closed 4 years ago
Hi @ryanf12 , that sounds terribly wrong. Can you share in what environment you ran the script?
I ran the following script and got the result fine.
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: 'test.csv',
header: [
{id: 'name', title: 'NAME'},
{id: 'lang', title: 'LANGUAGE'}
]
});
const records = [
{name: 'Bob', lang: '400,300,200,100,150,250,400,450'},
{name: 'Mary', lang: 'English'}
];
csvWriter.writeRecords(records)
.then(() => {
console.log('...Done');
});
$ node app
...Done
$ cat test.csv
NAME,LANGUAGE
Bob,"400,300,200,100,150,250,400,450"
Mary,English
Hi @ryanf12 , is this still an issue? I'm closing this for now, but if you've got more information to share, feel free to reopen it.
If you run the example file and replace the records with numerical values - it does not seem to return the expected results:
This will output:
Everything after the 5th index is converted to 000. In this example, the 250,400,450 will be converted to 000, 000, 000.
A workaround is to add a string into the data, like this: {name: 'Bob', lang: '400,300,200,100,150,250,400,450, string'}. Is there a way to write an array of numbers to a csv with this without adding in a string to the data?