I’m writing a spreadsheet (ods) using odfpy but I can’t figure out how to make it use bold text for a cell.
Advertisement
Answer
You have to define a style for the "table-cell"
family, for example:
JavaScript
x
19
19
1
from odf import opendocument
2
from odf.table import Table, TableRow, TableCell
3
from odf.style import Style, TextProperties
4
from odf.text import P
5
6
basedoc = opendocument.OpenDocumentSpreadsheet()
7
boldstyle = Style(name="BoldStyle", family="table-cell")
8
boldstyle.addElement(TextProperties(attributes={"fontweight": "bold"}))
9
basedoc.styles.addElement(boldstyle)
10
11
sheet = Table(name="Test")
12
tablerow = TableRow()
13
cell = TableCell(valuetype="string", stylename=boldstyle)
14
cell.addElement(P(text="bold cell"))
15
tablerow.addElement(cell)
16
sheet.addElement(tablerow)
17
basedoc.spreadsheet.addElement(sheet)
18
basedoc.save("test.ods")
19