ExcelJS V3.9.* | ExcelJS v4 |
---|---|
stream.pipe(workbook.xlsx.createInputStream()); |
await workbook.xlsx.read(stream) |
While upgrading to version 4 you get more ways to stream reading file.
We strongly recommend using this way, because it's 20% faster than any other and you get flow control
const workbook = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx');
for await (const worksheetReader of workbookReader) {
for await (const row of worksheetReader) {
// ...
// continue, break, return
}
}
const options = {
sharedStrings: 'emit',
hyperlinks: 'emit',
worksheets: 'emit',
};
const workbook = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx', options);
for await (const {eventType, value} of workbook.parse()) {
switch (eventType) {
case 'shared-strings':
// value is the shared string
case 'worksheet':
// value is the worksheetReader
case 'hyperlinks':
// value is the hyperlinksReader
}
}
const options = {
sharedStrings: 'emit',
hyperlinks: 'emit',
worksheets: 'emit',
};
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('./file.xlsx', options);
workbookReader.read();
workbookReader.on('worksheet', worksheet => {
worksheet.on('row', row => {
});
});
workbookReader.on('shared-strings', sharedString => {
// ...
});
workbookReader.on('hyperlinks', hyperlinksReader => {
// ...
});
workbookReader.on('end', () => {
// ...
});
workbookReader.on('error', (err) => {
// ...
});