Reputation: 23276
I create a CSV from javascript array of objects using the json2csv module. This is what I do
const list = [{name: "xyz", city: "abc"},{name: "foo", city: "def"}];
const json2csvParser = new Parser({fields: headers});
const csv = json2csvParser.parse(list);
Now, for the CSV created by converting array of objects, I need to prepend a row (add a new row at the top) and fill only the first cell. It will look similar to the following
Here is what I tried:
const newLine = `"First Line
Second Line"`;
const updatedCSV = newLine + csv;
Now, if I open this CSV using google spreadsheet
, it shows the prepended value in cell, with line breaks. But if I open the same in Microsoft Excel
, it shows as follows:
There are multiple rows created and "
are also visible. How can I make it seamless, so that it opens the same everywhere, which always shows one row with multiple line breaks. I need to be able to add the line breaks within a cell.
I referred to
but it did not help.
When I try to open the file using a text editor, this is how it looks like:
Upvotes: 1
Views: 2945