Some program saves xl/SharedStrings.xml instead of xl/sharedStrings.xml, and openpyxl cannot load such file as workbook
Prerequesites: OS: Windows 10 21H2, tried with Ubuntu 22.04.1 LTS on Windows 10 x86_64 and openSUSE Tumbleweed 20230211 on Windows 10 x86_64 Python version: Python 3.10.10(Win), 3.10.6(Ubuntu), 3.10.9(openSUSE) openpyxl version: openpyxl 3.1.1 on all systems
Steps to reproduce:
- try to openpyxl.load_workbook(filename="bad.xlsx")
Expected behaviour: loading of workbook
Experienced behaviour: crash with error that xl/sharedStrings.xml is missing.
Files that can be used to reproduce this behaviour:
-
File that have xl/SharedStrings.xml instead of xl/sharedStrings.xml bad.xlsx
-
File re-saved with LibreOffice Writer: good.xlsx
-
Script that reproduces the error: poc.py
Console outputs:
$ cat poc.py
import sys
import openpyxl
file = sys.argv[1]
workbook = openpyxl.load_workbook(filename=file, read_only=True)
print("all good")
$ py poc.py good.xlsx
all good
$ py poc.py bad.xlsx
Traceback (most recent call last):
File "/mnt/c/Users/_/Documents/_/_/_/test/poc.py", line 6, in <module>
workbook = openpyxl.load_workbook(filename=file, read_only=True)
File "/home/_/.local/lib/python3.10/site-packages/openpyxl/reader/excel.py", line 346, in load_workbook
reader.read()
File "/home/_/.local/lib/python3.10/site-packages/openpyxl/reader/excel.py", line 289, in read
self.read_strings()
File "/home/_/.local/lib/python3.10/site-packages/openpyxl/reader/excel.py", line 146, in read_strings
with self.archive.open(strings_path,) as src:
File "/usr/lib64/python3.10/zipfile.py", line 1514, in open
zinfo = self.getinfo(name)
File "/usr/lib64/python3.10/zipfile.py", line 1441, in getinfo
raise KeyError(
KeyError: "There is no item named 'xl/sharedStrings.xml' in the archive"
$ unzip -l good.xlsx
Archive: good.xlsx
Length Date Time Name
--------- ---------- ----- ----
887 2023-02-14 08:35 xl/workbook.xml
7118 2023-02-14 08:35 xl/styles.xml
2148 2023-02-14 08:35 xl/worksheets/sheet1.xml
408 2023-02-14 08:35 xl/_rels/workbook.xml.rels
567 2023-02-14 08:35 docProps/core.xml
442 2023-02-14 08:35 docProps/app.xml
571 2023-02-14 08:35 _rels/.rels
1231 2023-02-14 08:35 [Content_Types].xml
--------- -------
13372 8 files
unzip -l bad.xlsx
Archive: bad.xlsx
Length Date Time Name
--------- ---------- ----- ----
1271 2023-02-14 14:35 [Content_Types].xml
204 2023-02-14 14:35 xl/comments1.xml
158 2023-02-14 14:35 xl/SharedStrings.xml
2099 2023-02-14 14:35 xl/styles.xml
592 2023-02-14 14:35 xl/workbook.xml
207 2023-02-14 14:35 xl/drawings/drawing1.xml
427 2023-02-14 14:35 xl/drawings/vmlDrawing1.vml
145 2023-02-14 14:35 xl/drawings/_rels/drawing1.xml.rels
1418 2023-02-14 14:35 xl/worksheets/sheet1.xml
596 2023-02-14 14:35 xl/worksheets/_rels/sheet1.xml.rels
580 2023-02-14 14:35 xl/_rels/workbook.xml.rels
305 2023-02-14 14:35 _rels/.rels
--------- -------
8002 12 files