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.

2 thoughts on “openpyxl’s “load_workbook” return empty list of sheets

  1. Hi Kenneth,
    I have the same issue with my xlsx file, although it is a “Excel Workbook (xslx)”. Saveing back and forth between the two formats or even xls does not help. Do you have any idea how to fix this?

  2. Hi. First, let me apologize for the delayed response – I wasn’t aware of you comment until just now.

    I’m not too familiar with the neither the Python library itself nor xlsx formats, so unfortunately I don’t know what may be causing your issue. If your not already using Microsoft Excel to edit and save the files, you could check if that makes any difference. Other than that I suggest you reach out to the Python community (for example on Reddit) and see if that leads somewhere.

    Best of luck.

Leave a Reply

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

%d bloggers like this: