javascript - 将多个excel文件转换为json

标签 javascript json node.js excel

我正在尝试将多个 excel 文件转换为多个 json 文件。我一直在研究一些 nodejs 库,但不确定哪个库适合。是否有或方法可以读取多个excel文件并将它们转换为相应的json文件。

我正在查看这个特定的图书馆。 https://www.npmjs.com/package/convert-json

var cv2json = require('../');

var csv_trans = cv2json.xls('./test/test.xls', options /* optional */, function(err, result) {
  if(err)
    console.error(err);
  else 
    console.log(result);
    // result should be a json object or array. 
})

我看到他们正在传递一个 excel 文件并将其转换为 json-object。有没有一种方法可以传递多个文件参数并获取它们对应的 json 对象。

最佳答案

只需使用循环

var files = [
  './path/to/file1.xls',
  './path/to/file2.xls'
]

files.forEach(function(file) {
  cv2json.xls(file, function(err, result) {
    // do something with result
  }) 
})

关于javascript - 将多个excel文件转换为json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29659058/

相关文章:

javascript - 在 joint.js 中读取 JSON?

json - 将 JSON 字符串从 fetch 转换为 object

ruby-on-rails - 来自 cloudfront 的动态内容 - 我可以放置来自 Rails 的 API 结果 (JSON) 吗?

node.js - 错误 [ERR_STREAM_DESTROYED] : Cannot call write after a stream was destroyed with Winston

node.js - 问题模拟 Node 模块

javascript - 在页面加载时启动 simplemodal

javascript - 使用 jquery/javascript 读取值

javascript - 列表更改 onclick

python - 解析数据以使用 Python 创建 json 数据对象

node.js - NodeJS - 通过 URL 模式构建与日期相关的 Mongoose 查询