Skip to content

Commit 9f792cd

Browse files
authored
CLN: Better method of determining read-only status of openpyxl worksheet (#39793)
1 parent fc9fdba commit 9f792cd

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

pandas/io/excel/_openpyxl.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:
538538

539539
version = LooseVersion(get_version(openpyxl))
540540

541-
# There is no good way of determining if a sheet is read-only
542-
# https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1605
543-
is_readonly = hasattr(sheet, "reset_dimensions")
544-
545-
if version >= "3.0.0" and is_readonly:
541+
if version >= "3.0.0" and self.book.read_only:
546542
sheet.reset_dimensions()
547543

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

559-
if version >= "3.0.0" and is_readonly and len(data) > 0:
555+
if version >= "3.0.0" and self.book.read_only and len(data) > 0:
560556
# With dimension reset, openpyxl no longer pads rows
561557
max_width = max(len(data_row) for data_row in data)
562558
if min(len(data_row) for data_row in data) < max_width:

0 commit comments

Comments
 (0)