简体   繁体   English

将数据正确导出到 CSV 文件

[英]export data to a CSV file properly

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.我尝试将数据导出到 CSV 但我有一个小问题,因为当我这样做时,保存的 CSV 没有正确保存。 (I use react-csv library) (我使用react-csv库)

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:但如果我这样做,CSV 保存看起来像这样:

在此处输入图像描述

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!非常感谢!

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.在 excel 中打开 CSV 文件时有两个选项,我认为您以某种方式选择了“固定宽度”选项,这是一个非默认选项。 If you can adjust that setting and still got the issue lmk.如果您可以调整该设置但仍然遇到问题 lmk.

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.其次,它可能是您的 csv 应用程序打开。 Are you using Excel, Numbers or OpenOffice, or Google Docs?您使用的是 Excel、Numbers 或 OpenOffice,还是 Google Docs? It looks like you're importing a csv and using incorrect delimitation.看起来您正在导入 csv 并使用不正确的分隔符。

Last thing is it could be the formatting of the text.最后一件事是它可能是文本的格式。

Also, you could just use JavaScript natively or jQuery?此外,您可以直接使用 JavaScript 还是 jQuery?

Few suggestions.几个建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM