Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions frictionless/formats/excel/parsers/__spec__/test_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def test_xlsx_parser_format_error_sheet_by_index_not_existent():
assert error.note == 'Excel document "data/sheet2.xlsx" does not have a sheet "3"'


def test_xlsx_parser_missing_extra_dependency(monkeypatch: pytest.MonkeyPatch):
# https://github.com/frictionlessdata/frictionless-py/issues/1756
monkeypatch.setitem(sys.modules, "openpyxl", None)
monkeypatch.delitem(platform.__dict__, "openpyxl", raising=False)
resource = TableResource(path="data/table.xlsx")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
assert excinfo.value.error.note == 'Please install "frictionless[excel]"'


def test_xlsx_parser_sheet_by_name():
path = "data/sheet2.xlsx"
control = formats.ExcelControl(sheet="Sheet2")
Expand Down
5 changes: 4 additions & 1 deletion frictionless/formats/excel/parsers/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ def read_cell_stream_create(self):
# Get book
# To fill merged cells we can't use read-only because
# `sheet.merged_cell_ranges` is not available in this mode
# NOTE: resolve the dependency outside the try/except so that a missing
# `frictionless[excel]` install is not reported as an invalid excel file
openpyxl = platform.openpyxl
try:
warnings.filterwarnings("ignore", category=UserWarning, module="openpyxl")
book = platform.openpyxl.load_workbook(
book = openpyxl.load_workbook(
self.loader.byte_stream,
read_only=not control.fill_merged_cells,
data_only=True,
Expand Down