I want add data to new column in csv file. I using Javascript. I try with '\r\n'
but not work. Comma make new row in same column.
for (var i = 0, l = mydata.length; i < l; ++i) {
csvRows.push(mydata[i].join(','));
}
csvRows.push('\r\n'); //here want to go in second column
csvRows.push(mydata[0].join(',')); //this want write in second column first row
var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'file.csv';
document.body.appendChild(a);
a.click();
What I must push in csvRows
to make new column? FIDDLE is similar example.
I want add data to new column in csv file. I using Javascript. I try with '\r\n'
but not work. Comma make new row in same column.
for (var i = 0, l = mydata.length; i < l; ++i) {
csvRows.push(mydata[i].join(','));
}
csvRows.push('\r\n'); //here want to go in second column
csvRows.push(mydata[0].join(',')); //this want write in second column first row
var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'file.csv';
document.body.appendChild(a);
a.click();
What I must push in csvRows
to make new column? FIDDLE is similar example.
-
Looks like you need to loop through every thing in the array and add
,
. You just can't push something here. – Praveen Kumar Purushothaman Commented Jul 7, 2016 at 12:51 -
And please plete all the inplete codes!
csvRows
,mydata
,l
, etc. – Praveen Kumar Purushothaman Commented Jul 7, 2016 at 12:53 - @PraveenKumar I update question. In fiddle is similar example how it's work. – Nejc Galof Commented Jul 7, 2016 at 12:55
- Check my answer. Gives you some idea. – Praveen Kumar Purushothaman Commented Jul 7, 2016 at 12:55
- I have updated my answer. – Praveen Kumar Purushothaman Commented Jul 7, 2016 at 12:59
2 Answers
Reset to default 4Problem is specific when I open with Microsoft Excell. When I try with other programs, this works.
In Microsoft Excell work for me, if I change ,
to ;
Let's try here:
var data = [
"Col1,Col2,Col3",
"Col4,Col5,Col6"
];
console.log(data);
But if you wanna add one more column, you need:
var data = [
"Col1,Col2,Col3",
"Col4,Col5,Col6"
];
for (var i = 0; i < data.length; i++)
data[i] += ",NewCol" + (i + 1);
console.log(data);