[BUG] Incorrect Worksheet Name on Streaming XLSX Reader
whizdummy opened this issue ยท 4 comments
๐ Bug Report
I am having problems getting correct worksheet name when using streaming xlsx reader (async iteration). The first worksheet always defaults to Sheet1 regardless of name.
Lib version: 4.1.0
Steps To Reproduce
const workbook = new stream.xlsx.WorkbookReader('path/to/Sample Template.xlsx', {});
for await (const worksheetReader of workbook) {
console.log('sheet name:', worksheetReader.name); // It always outputs Sheet1
}
The expected behaviour:
Worksheet name should be Sum Worksheet instead of Sheet1.
@whizdummy I found that there is indeed something unreasonable in the XLSX
reader.
@alubbe Do you have time to answer these questions?
Source Code
The function sheet-xform.js should be used to resolve worksheet names.
// sheet-xform.js
parseOpen(node) {
if (node.name === 'sheet') {
this.model = {
name: utils.xmlDecode(node.attributes.name),
id: parseInt(node.attributes.sheetId, 10),
state: node.attributes.state,
rId: node.attributes['r:id'],
};
return true;
}
return false;
}
The following code will build an instance of worksheet-reader
, including the name of the worksheet, such as Sheet1
and Sheet2
, etc.
// workbook-reader.js
*_parseWorksheet(iterator, sheetNo) {
this._emitEntry({type: 'worksheet', id: sheetNo});
const worksheetReader = new WorksheetReader({workbook: this, id: sheetNo, iterator, options: this.options});
if (this.options.worksheets === 'emit') {
yield {eventType: 'worksheet', value: worksheetReader};
}
}
I think that workbook-xform.js should be used to parse the workbook.xml file.
// const WorkbookPropertiesManager = require('../../xlsx/xform/book/workbook-properties-xform');
const WorkbookManager = require('../../xlsx/xform/book/workbook-xform');
@Alanscut that looks reasonable. Could you put together a PR with a potential fix (or an attempt of it) and with a test using the provided xlsx?
Do you plan on addressing this any time soon?