fix in the export of excel lists

This commit is contained in:
2026-06-30 11:32:17 +02:00
parent 40c3970719
commit 36c391e99c
+15 -12
View File
@@ -37,20 +37,23 @@ def generate_library_excel(items):
item.get("ReturnDate", ""), item.get("ReturnDate", ""),
item.get("Anschaffungskosten", "") item.get("Anschaffungskosten", "")
] ]
ws.append(row)
for col in ws.columns: # FIX: Clean the row data INSIDE the loop for every single item
max_length = 0 clean_row = []
column = col[0].column_letter for value in row:
for cell in col: if isinstance(value, list):
try: # Converts ['A', 'B'] to "A, B" and an empty list [] to an empty string ""
if len(str(cell.value)) > max_length: clean_row.append(", ".join(map(str, value)) if value else "")
max_length = len(str(cell.value)) elif isinstance(value, dict):
except: # Just in case there is an embedded MongoDB sub-document
pass clean_row.append(str(value))
ws.column_dimensions[column].width = min(max_length + 2, 50) else:
clean_row.append(value)
# Append the safe, flattened row to the worksheet
ws.append(clean_row)
excel_buffer = io.BytesIO() excel_buffer = io.BytesIO()
wb.save(excel_buffer) wb.save(excel_buffer)
excel_buffer.seek(0) excel_buffer.seek(0)
return excel_buffer return excel_buffer