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());
I have the following document:
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.
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?
steps to read a value from Excel : // create object for workbook let wb:Workbook = new Workbook(); From the Workbook object, we have to use readFile along with file type, here xlsx is file type. Create then block to resolve the promise to get values of the workbook.
ExcelJS is a JavaScript library for reading, manipulating and writing spreadsheet data in XLSX format.
exceljs doesn't support xls , which is the older, proprietary format. xlsx is an open standard and just zipped xml, which is easy to support.
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));
});
});
And in case you are using file as ArrayBuffer (for example file was read on client with FileReader.readAsArrayBuffer()), then to make it load with this lib you have to do the next:
let workbook = new Excel.Workbook();
let stream = new Stream.Readable();
stream.push(file); // file is ArrayBuffer variable
stream.push(null);
workbook.xlsx.read(stream).then((workbook)=> {
// get worksheet, read rows, etc
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With