I am using Python 2.7
& openpyxl==2.5.11
.
I want to read .xlsx
files using openpyxl
. Initially I was testing with files downloaded from Google Drive and everything worked nice.
Now, I tried to load some files generated with Microsoft Excel, but I see this error:
raise IOError("File contains no valid workbook part")
I tried to print some variables and figure out on my own, but I lack deeper knowledge about Excel files and there are some levels of abstraction I couldn't quickly understand.
Here is the relevant piece of code where the error is raised (excel.py
):
def _find_workbook_part(package):
workbook_types = [XLTM, XLTX, XLSM, XLSX]
for ct in workbook_types:
part = package.find(ct)
if part:
return part
# some applications reassign the default for application/xml
defaults = set((p.ContentType for p in package.Default))
workbook_type = defaults & set(workbook_types)
if workbook_type:
return Override("/" + ARC_WORKBOOK, workbook_type.pop())
raise IOError("File contains no valid workbook part")
I have the problem on both OSX & Ubuntu, if that's relevant.
EDIT: I am not capable to reproduce the issue with files I have generated on my own. I think the problem can only be reproduced with older files. The people who had the issue were using Excel 2008 or older version to create the files, so maybe that's the problem?
Thanks in advance