fix: Excel-Glättung als dokumentartigen Lesefluss ausgeben

This commit is contained in:
2026-07-22 14:44:00 +02:00
parent 0d6361d3ff
commit e5767add73
6 changed files with 23 additions and 18 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ class DocumentationConfig(PluginConfig):
name = "netbox_documentation"
verbose_name = "NetBox Dokumentation"
description = "Wiki und Office-Dokumentation direkt in NetBox"
version = "0.5.2"
version = "0.5.3"
author = "LKE"
base_url = "documentation"
min_version = "4.0.0"
+1 -1
View File
@@ -134,7 +134,7 @@ class ImportForm(forms.Form):
required=False,
label=help_label(
"Excel-Tabellen glätten",
"Wandelt jede Tabellenzeile in einen lesbaren Textblock aus Feldnamen und Wert um, statt eine Tabelle zu erzeugen.",
"Übernimmt alle Zellen ohne Tabelle in Lesereihenfolge als dokumentartigen Text. Es werden keine Datensatz- oder Feldbezeichnungen erzeugt.",
),
)
category = forms.ModelChoiceField(
+14 -9
View File
@@ -60,17 +60,22 @@ def _render_excel_rows(rows, flatten=False):
header, body = rows[0], rows[1:]
if not flatten:
return tabulate(body, headers=header, tablefmt="github")
# Document-style flattening: retain every cell in reading order without
# inventing record headings or field/value labels. Cells in one Excel row
# become lines in one paragraph; Excel rows are separated by a blank line.
blocks = []
for number, row in enumerate(body, 1):
values = []
for column, value in zip(header, row):
if value == "":
continue
label = column or "Feld"
values.append(f"**{label}:** {value}")
for row in rows:
values = [_escape_markdown_text(value) for value in row if value != ""]
if values:
blocks.append(f"### Datensatz {number}\n\n" + " \n".join(values))
return "\n\n".join(blocks) or "_Keine Datensätze_"
blocks.append(" \n".join(values))
return "\n\n".join(blocks) or "_Keine Inhalte_"
def _escape_markdown_text(value):
value = str(value).replace("\\", "\\\\")
for character in ("*", "_", "[", "]", "<", ">", "#", "|"):
value = value.replace(character, f"\\{character}")
return value.replace("\r\n", " \n").replace("\r", " \n").replace("\n", " \n")
def _xlsx(content, flatten=False):