博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node 导出csv文件_如何使用Node.js编写CSV文件
阅读量:2501 次
发布时间:2019-05-11

本文共 1519 字,大约阅读时间需要 5 分钟。

node 导出csv文件

A great library you can use to quickly write an array of objects to a CSV file using Node.js is .

可以使用Node.js将数组快速写入CSV文件的出色库是 。

Many other libraries exist, of course. I found this useful for a project of mine where I had to generate a one-time CSV file, so I wrote this little tutorial.

当然,还有许多其他库。 我发现这对我的一个项目很有用,因为我必须生成一个一次性CSV文件,因此我写了这个小教程。

Using a -based library like might suits your needs in more performance-oriented applications.

使用像这样的基于的库可能适合您更注重性能的应用程序中的需求。

Install it using:

使用以下方法安装:

npm install objects-to-csv

then require it in your Node.js code:

然后在您的Node.js代码中要求它:

const ObjectsToCsv = require('objects-to-csv')

When you have an array of objects ready to write to CSV, initialize a new ObjectsToCsv object instance:

当您准备好要写入CSV的对象数组时,请初始化一个新的ObjectsToCsv对象实例:

const csv = new ObjectsToCsv(list)

then call csv.toDisk(), passing the file you want to write to (relative to your app base path):

然后调用csv.toDisk() ,传递您要写入的文件(相对于您的应用程序基本路径):

await csv.toDisk('./list.csv')

This is a promise-based API and I used await, so you need to call this inside an function.

这是一个基于promise的API,我使用了await ,因此您需要在一个函数中调用它。

The column names in the CSV are automatically inferred from the object properties names.

CSV中的列名称是根据对象属性名称自动推断出来的。

Note that this command overwrites the existing content of the file. To append to that file, pass a second object with the append property set to true:

请注意,此命令将覆盖文件的现有内容。 要附加到该文件,请传递第二个对象,将append属性设置为true:

await csv.toDisk('./list.csv', { append: true })

翻译自:

node 导出csv文件

转载地址:http://wlqgb.baihongyu.com/

你可能感兴趣的文章
关于yum Error: Cannot retrieve repository metadata (repomd.xml) for repository:xxxxxx.
查看>>
2020-11-18
查看>>
Docker面试题(二)
查看>>
【NOI 2018】归程(Kruskal重构树)
查看>>
注册用户
查看>>
TZC Intercommunication System
查看>>
HDU 4571 SPFA+DP
查看>>
centos 创建以日期为名的文件夹
查看>>
Java Timer触发定时器
查看>>
Page Object设计模式
查看>>
程序的基础知识
查看>>
在VIM中使用GDB调试 – 使用vimgdb
查看>>
python爬虫---从零开始(五)pyQuery库
查看>>
POJ2236(KB5-A)
查看>>
Centos MySQL数据库迁移详细步骤
查看>>
2初出茅庐--初级篇2.1
查看>>
新建 WinCE7.0 下的 Silverlight 工程
查看>>
腾讯的张小龙是一个怎样的人?
查看>>
jxl写入excel实现数据导出功能
查看>>
linux文件目录类命令|--cp指令
查看>>