From 40dcfd450fafdff72eadcd4c88857ca40ac90698 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 9 Jan 2025 18:25:00 +1100 Subject: [PATCH] See #5940. Fix bug where using preserve existing in IfcCSV didn't fully purge extra rows, possibly leading to orphaned data (which LibreOffice will render as 0 if it is a number value type) --- src/ifccsv/ifccsv.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ifccsv/ifccsv.py b/src/ifccsv/ifccsv.py index 247946236a..34e4b37b32 100755 --- a/src/ifccsv/ifccsv.py +++ b/src/ifccsv/ifccsv.py @@ -324,10 +324,9 @@ class IfcCsv: # If the DataFrame has fewer rows than the table, blank out the extra rows num_rows_table = len(first_table.getElementsByType(TableRow)) - 1 # Exclude header row if len(df) < num_rows_table: - for i in range(len(df) + 1, num_rows_table + 1): # +1 to account for header - for cell in first_table.getElementsByType(TableRow)[i].getElementsByType(TableCell): - for item in cell.childNodes: - cell.removeChild(item) + rows = first_table.getElementsByType(TableRow) + for i in reversed(range(len(df) + 1, num_rows_table + 1)): # +1 to account for header + first_table.removeChild(rows[i]) ods_document.save(output) else: