openpyxl’s “load_workbook” return empty list of sheets

openpyxl’s “load_workbook” return empty list of sheets

Consider this code:

workbook = load_workbook(filename='/app/file.xlsx', data_only=True)
print("Sheet names: " + str(workbook.sheetnames))
worksheet = workbook['Sheet1']

When using one of my xlsx-files as input, my code produced the output Sheet names: [] followed by this expection:

'Worksheet Sheet1 does not exist.'

After some investigating, I found that the file had been saved as “Strict Open XML Spreadsheet (xlsx)” instead of “Excel Workbook (xslx)”. Both files for some reason have the same file extension, but the former was not supported by the openpyxl library. Saving the file as “Excel Workbok (xslx)” got the code working again.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: