MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / write_ods

Method write_ods

src/ifcfm/ifcfm/__init__.py:242–290  ·  view source on GitHub ↗
(self, output: str)

Source from the content-addressed store, hash-verified

240 writer.writerow(row)
241
242 def write_ods(self, output: str) -> None:
243 doc = OpenDocumentSpreadsheet()
244
245 for key, value in self.config.get("colours", {}).items():
246 color_str = "#" + value
247
248 style = Style(name=key, family="table-cell")
249 style.addElement(TableCellProperties(backgroundcolor="#" + value))
250 doc.automaticstyles.addElement(style)
251
252 style = Style(name=f"{key}-table", family="table")
253 style.addElement(props := TableProperties())
254 # odfpy grammar is outdated and it doesn't allow to set it with `setAttribute`.
255 props.setAttrNS(odf_ns.TABLEOOONS, "tab-color", color_str)
256 doc.automaticstyles.addElement(style)
257
258 for category, data in self.categories.items():
259 category_data = self.config.get("categories", {}).get(category, {})
260 colours = category_data.get("colours", ())
261
262 table = Table(name=category)
263 if category_colour := category_data.get("colour", None):
264 table.setAttribute("stylename", f"{category_colour}-table")
265
266 tr = TableRow()
267 for header in data["headers"]:
268 tc = TableCell(valuetype="string", stylename="h")
269 tc.addElement(P(text=header))
270 tr.addElement(tc)
271 table.addElement(tr)
272 for row in data["rows"]:
273 tr = TableRow()
274 c = 0
275 for col in row:
276 if c >= len(colours):
277 cell_format = "n"
278 else:
279 cell_format = colours[c]
280 tc = TableCell(valuetype="string", stylename=cell_format)
281 tc.addElement(P(text=str(col)))
282 tr.addElement(tc)
283 c += 1
284 table.addElement(tr)
285 doc.spreadsheet.addElement(table)
286
287 if len(output) > 4 and output[-4:].lower() == ".ods":
288 output = output[0:-4]
289
290 doc.save(output, True)
291
292 def write_xlsx(self, output: str) -> None:
293 workbook = Workbook()

Callers 3

executeMethod · 0.95
executeMethod · 0.95
__main__.pyFile · 0.80

Calls 5

StyleClass · 0.90
lowerMethod · 0.80
itemsMethod · 0.45
getMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected