load_workbook fails if no strings in the workbook
Created originally on Bitbucket by peircej
With a file (generated by Excel 2008 for Mac) that contains no strings there seems to be no xl/sharedStrings.xml created, so excel.load_workbook fails with the following:
Traceback (most recent call last): File "/Users/jwp/code/psychopy/sandbox/xlsx.py", line 8, in wb = load_workbook('test.xlsx') File "/Users/jwp/code/thirdParty/openpyxl/src/openpyxl/reader/excel.py", line 50, in load_workbook string_table = read_string_table(xml_source = archive.get_from_name(arc_name = ARC_SHARED_STRINGS)) File "/Users/jwp/code/thirdParty/openpyxl/src/openpyxl/shared/zip.py", line 44, in get_from_name return self._zipfile.read(arc_name) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/zipfile.py", line 836, in read return self.open(name, "r", pwd).read() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/zipfile.py", line 859, in open zinfo = self.getinfo(name) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/zipfile.py", line 826, in getinfo 'There is no item named %r in the archive' % name) KeyError: "There is no item named 'xl/sharedStrings.xml' in the archive"
A quick fix is to do the following in load_workbook(), but you may want to insert a proper test into read_string_table() instead.
try:
string_table = read_string_table(xml_source = archive.get_from_name(arc_name = ARC_SHARED_STRINGS))
except:
string_table={}
cheers, Jon
PS let me know if you prefer a different means of reporting such issues