Unable to open file (list index out of range in _expand_named_style)
While trying to open a file I get following error:
File "/var/www/order/app/orders/models/order.py", line 260, in create_order_excel
order_wb = openpyxl.open(f'{current_app.root_path}/templates/order_template.xlsx')
File "/var/www/order/lib/python3.6/site-packages/openpyxl/reader/excel.py", line 315, in load_workbook
reader.read()
File "/var/www/order/lib/python3.6/site-packages/openpyxl/reader/excel.py", line 279, in read
apply_stylesheet(self.archive, self.wb)
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 192, in apply_stylesheet
stylesheet = Stylesheet.from_tree(node)
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 102, in from_tree
return super(Stylesheet, cls).from_tree(node)
File "/var/www/order/lib/python3.6/site-packages/openpyxl/descriptors/serialisable.py", line 103, in from_tree
return cls(**attrib)
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 93, in __init__
self.named_styles = self._merge_named_styles()
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 113, in _merge_named_styles
self._expand_named_style(style)
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 123, in _expand_named_style
xf = self.cellStyleXfs[named_style.xfId]
File "/var/www/order/lib/python3.6/site-packages/openpyxl/styles/cell_style.py", line 185, in __getitem__
return self.xf[idx]
IndexError: list index out of range
While debugging I've noticed that issue occurs when named_style.xfId
was 1556 (in my case) and length of self.cellStyleXfs.xf
was also 1556.
Having other Excel files are opened I believe the problematic file can be somehow changed to avoid the problem but the error gives no indication of what's wrong and I've no idea what can be changed.
The Excel file is attached.