-1

I tried to export data to a CSV but I have a little problem, because when I do it, the CSV saved is not correctly saved. (I use react-csv library)

I followed the guide from here and all the examples I found they basically do the same thing!

For example I have this data:

const csvData = [
  ["firstname", "lastname", "email"],
  ["Ahmed", "Tomi", "ah@smthing.co.com"],
  ["Raed", "Labes", "rl@smthing.co.com"],
  ["Yezzi", "Min l3b", "ymin@cocococo.com"]
];

In order to export it they suggest me to do this:

<CSVLink data={csvData}>Download me</CSVLink>;

But if I do so the CSV saved looks like this:

enter image description here

As you can see the data is set only on one column.

Did I do something wrong?

Would you like to show me the correct way to do it? Actually everything I found uses the approach above.

Thank you very much!

  • Have you tried referring to this link https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side – techie_questie Feb 10 '21 at 14:27

2 Answers2

0

There are two options while opening a CSV file in excel, I think you somehow choosed the option "fixed-width" which is a non-default option. If you can adjust that setting and still got the issue lmk.

mergen
  • 38
  • 8
0

Could be a number of issues. First thing comes to mind is your formatting is incorrect. Each column should be separated by its own brackets. [“firstname”],[“lastname”].

Secondly it could be your csv app opening. Are you using Excel, Numbers or OpenOffice, or Google Docs? It looks like you’re importing a csv and using incorrect delimitation.

Last thing is it could be the formatting of the text.

Also, you could just use JavaScript natively or jQuery?

Few suggestions.

apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69