Skip to content

CLN: Better method of determining read-only status of openpyxl worksheet #39793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pandas/io/excel/_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:

version = LooseVersion(get_version(openpyxl))

# There is no good way of determining if a sheet is read-only
# https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1605
is_readonly = hasattr(sheet, "reset_dimensions")

if version >= "3.0.0" and is_readonly:
if version >= "3.0.0" and self.book.read_only:
sheet.reset_dimensions()

data: List[List[Scalar]] = []
Expand All @@ -556,7 +552,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:
# Trim trailing empty rows
data = data[: last_row_with_data + 1]

if version >= "3.0.0" and is_readonly and len(data) > 0:
if version >= "3.0.0" and self.book.read_only and len(data) > 0:
# With dimension reset, openpyxl no longer pads rows
max_width = max(len(data_row) for data_row in data)
if min(len(data_row) for data_row in data) < max_width:
Expand Down