【问题标题】:How to read and write xlxs and csv file using nodejs如何使用node js读写xlsx和csv文件
【发布时间】:2021-02-12 16:27:36
【问题描述】:

首先,我想在 node.js 中上传 .xlxs 和 .csv 文件。然后我想读取这个文件,编辑这个文件,还想把这个文件保存在数据库中的猫鼬模式中。 我是 node.js 的新手,我想学习 node 后端 请指导我,我该怎么做?这可能吗?

【问题讨论】:

  • 如果有帮助请记得采纳答案

标签: node.js reactjs express node-modules


【解决方案1】:

node 中读写文件使用fs 模块。它已经包含在核心节点中,所以只需包含它

const fs = require('fs')

// synchronous version that will wait until the whole file is read
let file_data = fs.readFileSync('/file/path/file.csv' , 'utf-8') 

// async version
fs.readFile('/file/path/file.csv' , 'utf-8', (err, file_data) => {

 if (err)
   console.error(err)
else
   console.info(file_data)
   // file_data is your data as string

})

如果您特别需要阅读和编辑 csv/xlsx,则需要浏览 NPM 以获取有助于解决此问题的软件包。

【讨论】:

    【解决方案2】:

    您可以使用sheetjs轻松做到这一点

    看这个例子:https://github.com/SheetJS/sheetjs/tree/master/demos/server

    【讨论】:

      猜你喜欢
      • 2016-12-30
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 2017-05-25
      相关资源
      最近更新 更多