From dbf3e7a62ab2352fad69a20a15f3afef38d3db3e Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 23 Jul 2026 16:13:38 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Farben=20freier=20Excel-Zellen=20beim=20?= =?UTF-8?q?Gl=C3=A4tten=20bewahren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- netbox_documentation/__init__.py | 2 +- netbox_documentation/importers.py | 9 +++++++-- pyproject.toml | 2 +- tests/test_importers.py | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/netbox_documentation/__init__.py b/netbox_documentation/__init__.py index b9138b5..fcb100f 100644 --- a/netbox_documentation/__init__.py +++ b/netbox_documentation/__init__.py @@ -5,7 +5,7 @@ class DocumentationConfig(PluginConfig): name = "netbox_documentation" verbose_name = "NetBox Dokumentation" description = "Wiki und Office-Dokumentation direkt in NetBox" - version = "0.7.9" + version = "0.7.10" author = "LKE" base_url = "documentation" min_version = "4.0.0" diff --git a/netbox_documentation/importers.py b/netbox_documentation/importers.py index c6c593c..dd0cc50 100644 --- a/netbox_documentation/importers.py +++ b/netbox_documentation/importers.py @@ -382,9 +382,14 @@ def _render_flattened_worksheet(sheet, workbook, max_rows=None): tables_starting_here.append(bounds) rendered_tables.add(bounds) continue - value = sheet.cell(row=row_number, column=column_number).value + cell = sheet.cell(row=row_number, column=column_number) + value = cell.value if value not in (None, ""): - ordinary_values.append(escape(str(value)).replace("\n", "
")) + rendered_value = escape(str(value)).replace("\n", "
") + style = _excel_cell_style(cell, workbook) if cell.has_style else "" + if style: + rendered_value = f'{rendered_value}' + ordinary_values.append(rendered_value) if ordinary_values: blocks.append("

" + "
".join(ordinary_values) + "

") for min_col, min_row, max_col, max_row in tables_starting_here: diff --git a/pyproject.toml b/pyproject.toml index 0a8c06c..18529e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-documentation" -version = "0.7.9" +version = "0.7.10" description = "Integrated Markdown wiki and office document importer for NetBox" readme = "README.md" requires-python = ">=3.10" diff --git a/tests/test_importers.py b/tests/test_importers.py index fc6681a..8510ebf 100644 --- a/tests/test_importers.py +++ b/tests/test_importers.py @@ -231,3 +231,21 @@ def test_excel_flatten_preserves_colors_of_explicit_excel_tables(): assert results[0].body_format == "html" assert results[0].markdown.count("background-color: #a5bf60") == 2 assert results[0].markdown.count("color: #ffffff") == 2 + + +def test_excel_flatten_preserves_colored_cells_outside_tables(): + workbook = Workbook() + sheet = workbook.active + sheet["A1"] = "Wichtiger Hinweis" + sheet["A1"].fill = PatternFill(fill_type="solid", fgColor="FFF3BF") + sheet["A1"].font = Font(color="9C2A2A", bold=True) + sheet["A3"] = "Normaler Text" + stream = BytesIO() + workbook.save(stream) + + results = import_excel_sheets(Upload(stream.getvalue(), "hinweis.xlsx"), flatten=True) + + assert results[0].body_format == "html" + assert '" in results[0].markdown + assert "