Description
🐛 Bug Report
I've created excel files using OpenPyXL and now want to modify these using ExcelJS. However, there are no sheets on the Workbook.worksheets array.
There was a single worksheet located at Workbook._worksheets on the undefined
property, but the others were missing.
I did some debugging, and found that the issue occurs at xlsx.js::353
, this.workbook.model = model
. The model properly loads and contains all the worksheets, but the setter doesn't handle them correctly.
In workbook.js::200
, const {id, name, state} = worksheetModel;
has id
undefined, so at some point the worksheet id is missing or not set properly. This may be caused by OpenPyXL not saving the worksheet properly?
Lib version: 3.8.2
Openpyxl: 3.0.3
Steps To Reproduce
Python
wb = Workbook()
example_row = ['1', '2', '3']
ka_list = wb.create_sheet('KA lijst')
ka_list.append(example_row)
wb.save(f"output/example.xlsx")
JS
workbook = new Workbook();
await workbook.xlsx.readFile(__dirname + 'output/example.xlsx');
const kaWorksheet = workbook.getWorksheet('KA lijst');
// kaWorksheet is undefined
File with the incorrect behaviour:
lasschema.xlsx
The expected behaviour:
I would expect to be able to retrieve the specific sheet using getWorksheet('KA')
and be able to read its rows.
Potential fix:
In workbook-xform.js::160
we find the worksheet using rel.Target
. ( worksheet = model.worksheetHash[
xl/${rel.Target}]
)
For the given file, rel.Target
is "/xl/worksheets/sheet1.xml"
, including a '/xl/' already. The lookup with xl/xl/worksheets/sheet1.xml
therefore won't find it.
For example
if (rel.Target.startsWith('/xl/')) {
rel.Target = rel.Target.substr(4);
}
We could slice the "/xl"section off rel.Target when it's present to fix it.