Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
file = ...
pd.read_excel(
io=BytesIO(file.file.read()),
sheet_name="sheet_name",
header="header"
)
Issue Description
Since openpyxl 3.1.1, the code given above results in the following error:
Failed to process file: 'ReadOnlyWorksheet' object has no attribute 'defined_names'
Downgrading to openpyxl 3.1.0 fixes this issue. From the outside, it is not clear whether pandas or openpyxl needs to be fixed, even though it looks like a bug on openpyxl side. It is likely related to this issue which was marked as fixed in openpyxl 3.1.1: https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1947
Link to openpyxl changelog: https://openpyxl.readthedocs.io/en/stable/changes.html#id1
There is also a report on StackOverflow which has already gotten more than 4000 views: https://stackoverflow.com/questions/75440354/why-does-pandas-read-excel-fail-on-an-openpyxl-error-saying-readonlyworksheet
Expected Behavior
reading a file works just like with openpyxl 3.1.0
Installed Versions
Comment From: phofl
Hi, thanks for your report. We have already an issue for this, bug is indeed in openpyxl and not on our side
Comment From: jonathanloske
This is the issue that tracks this: https://github.com/pandas-dev/pandas/issues/51392