Fix #3610. Glitch where editing existing float cells in IfcCSV ODS files created new cells or didn't update.

This commit is contained in:
Dion Moult
2023-08-20 23:42:11 +10:00
parent 3d933d2abe
commit 822bc4c08c
+8 -8
View File
@@ -29,6 +29,7 @@ import ifcopenshell.util.element
import ifcopenshell.util.schema import ifcopenshell.util.schema
try: try:
from odf.namespaces import OFFICENS
from odf.opendocument import OpenDocumentSpreadsheet, load from odf.opendocument import OpenDocumentSpreadsheet, load
from odf.style import Style, TableCellProperties from odf.style import Style, TableCellProperties
from odf.table import Table, TableRow, TableCell from odf.table import Table, TableRow, TableCell
@@ -138,7 +139,7 @@ class IfcCsv:
for col_index, value in enumerate(row): for col_index, value in enumerate(row):
cell = self.get_col(table_row, col_index) cell = self.get_col(table_row, col_index)
self.set_cell_value(cell, str(value)) self.set_cell_value(cell, value)
# If the DataFrame has fewer rows than the table, blank out the extra rows # 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 num_rows_table = len(first_table.getElementsByType(TableRow)) - 1 # Exclude header row
@@ -158,14 +159,13 @@ class IfcCsv:
cell.removeChild(item) cell.removeChild(item)
if isinstance(value, (int, float)): if isinstance(value, (int, float)):
# Create a new cell with float value cell.setAttrNS(OFFICENS, "value-type", "float")
new_cell = TableCell(valuetype="float", value=str(value)) cell.setAttrNS(OFFICENS, "value", value)
cell.parentNode.insertBefore(new_cell, cell)
cell.parentNode.removeChild(cell)
else: else:
# Add string value in a text paragraph cell.setAttrNS(OFFICENS, "value-type", "string")
p_element = P(text=str(value)) cell.setAttrNS(OFFICENS, "value", str(value))
cell.addElement(p_element) p_element = P(text=str(value))
cell.addElement(p_element)
def get_row(self, table, row_index): def get_row(self, table, row_index):
rows = table.getElementsByType(TableRow) rows = table.getElementsByType(TableRow)