如何使用node.js读取Excel文件 [英] how to read an excel file using node.js
本文介绍了如何使用node.js读取Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用与 lambda 集成的 node.js 来读取 S3 中存在的 excel文件 .我的意思是代码应与excel文件进行交互并显示输出. 请帮助我解决这个问题.
I'm trying to read an excel file present in S3 using node.js integrated with lambda. I mean the code should interact with excel file and display the output. Please help me in this issue.
推荐答案
要使用Node.js从AWS Lambda中的S3中读取文件,您可以按照给定的步骤进行操作.要从节点js中的excel文件中读取数据,我更喜欢xlsx
包.要使用它,首先需要安装xlsx
节点程序包,然后按给定的步骤进行操作-
To read a file from S3 in AWS lambda with nodejs you can follow given steps. To read data from excel file in node js, I prefer xlsx
package. To use it, first you need to install xlsx
node package and then proceed as given -
npm i xlsx --save
然后,您可以将excel文件读为-
Then you can read excel file as -
const xlsx = require('xlsx');
var params = {
Bucket: "",
Key: ""
};
var file = s3.getObject(params).createReadStream();
var buffers = [];
file.on('data', function (data) {
buffers.push(data);
});
file.on('end', function () {
var buffer = Buffer.concat(buffers);
var workbook = xlsx.parse(buffer);
console.log("workbook", workbook);
var sheet_name_list = workbook.SheetNames;
//if you have multiple sheets
data = xlsx.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
for(var key in data){
console.log(data[key]['yourColumn']);
}
});
这篇关于如何使用node.js读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文