我正在尝试从节点js中的Excel工作表中检索数据。实际上我想在AWS Lambda(Node JS)中从AWS-S3对象执行相同的功能检索,但现在我正在尝试在本地机器中执行相同的操作。您可以帮我或者单独使用(在本地计算机或AWS Lambda中) 。
答案 0 :(得分:2)
尝试以下
拳头安装xlsx
包
npm i xlsx --save
使用下面的代码段
const XLSX = require('xlsx');
var workbook = XLSX.readFile('./assets/yourfile.xlsx');// ./assets is where your relative path directory where excel file is, if your excuting js file and excel file in same directory just igore that part
var sheet_name_list = workbook.SheetNames; // SheetNames is an ordered list of the sheets in the workbook
data = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]); //if you have multiple sheets
for(var key in data){
console.log(data[key]['yourColumn']);
}
更多信息请参阅文档here