问题描述
因此,根据官方文档,我应该能够使用以下内容读取Excel文档:
So according to the offical documentation i should be able to read an excel document using:
// read from a file
var workbook = new Excel.Workbook();
workbook.xlsx.readFile(filename)
.then(function() {
// use workbook
});
// pipe from stream
var workbook = new Excel.Workbook();
stream.pipe(workbook.xlsx.createInputStream());
我有以下文件:
我需要做的基本上是将每一行加载到一个对象中:
What i need to do is basicly to load each row into an object:
var excelObject = {competence1: '', competence2: ''}
然后将其保存到数组中.
And then save it into an array.
但是,文档并没有给我更多有关如何从此文件中读取内容的信息.它使用一个名为stream
的变量,但是此变量在任何地方都没有解释.
However the documentation doesnt give me more on how i might read from this file. It uses a variable called stream
however this variable is not explained anywhere.
有人知道这个插件并且知道我如何实现我的目标吗?
Does anyone know the plugin and know how i might achieve my goal?
推荐答案
var workbook = new Excel.Workbook();
workbook.xlsx.readFile(filename)
.then(function() {
var worksheet = workbook.getWorksheet(sheet);
worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
console.log("Row " + rowNumber + " = " + JSON.stringify(row.values));
});
});