py-xlsx icon indicating copy to clipboard operation
py-xlsx copied to clipboard

Error when opening xlsx file

Open quandyfactory opened this issue 14 years ago • 5 comments

FYI when I try to open an xlsx file, I get the following error:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    book = Workbook(path)
  File "C:\Python27\lib\site-packages\xlsx\__init__.py", line 54, in __init__
    self.domzip["xl/sharedStrings.xml"])
  File "C:\Python27\lib\site-packages\xlsx\__init__.py", line 94, in __init__
    self.__getIfInline(text))
  File "C:\Python27\lib\site-packages\xlsx\__init__.py", line 101, in __getIfInline
    for node in nodes])
AttributeError: 'NoneType' object has no attribute 'nodeValue'

I have verified that the file is in the specified path (the library throws an IOError if the path is wrong).

quandyfactory avatar Nov 10 '11 19:11 quandyfactory

Check the file "xl/sharedStrings.xml" inside the docx file (it is a zip file of xml files). Possibly there is an empty or something there that the code breaks on. Might need some additional checks inside the __getIfInline function to handle those instances.

I am not activly maintaining this library, but if you submit a patch to github, I will merge it into the code.

staale avatar Nov 11 '11 07:11 staale

Thanks. I'll look into that presently.

quandyfactory avatar Nov 16 '11 16:11 quandyfactory

There are no empty strings inside the xl/sharedStrings.xml file. The closest I can find is a string with a line break inside it:

<si><t>Jason Johnson _x000D_
dwilliam_x000D_
dwilliam_x000D_
dwilliam</t></si>

Would that cause an issue?


Edit - I tried removing all the line breaks inside strings in the xl/sharedStrings.xml file, but the issue persists.

Could the issue simply be that there are too many items? The sst element has the attributescount="132871" and uniqueCount="17591".

quandyfactory avatar Nov 16 '11 16:11 quandyfactory

If size was the problem, you would proabably get another type of error I would guess. I would recommend that you add some print or debug statements in the code, and try and figure out what goes wrong. I am not activly maintinging this as I no longer work in python or with excel documents. I will accept any patch you submit that fixes the issue though.

staale avatar Nov 17 '11 08:11 staale

Thanks. I'll try that. If I figure out how to fix it, I'll submit a patch. I'd rather not be working with Excel documents, either (though I do enjoy working in Python).

quandyfactory avatar Nov 17 '11 22:11 quandyfactory