doc=Document()
table = doc.add_table(rows = 13, cols = 5)
table.style = 'Table Grid'
row = table.rows[0]
row.cells[0].text = ('text').bold
I am trying to create a table and bold the text but cannot get the syntax right
The .text method on a cell just sets the cell contents in "plain text". If you want to format the font of that text (like make it bold), you have to access the text at the run level. Something like this will work but best for you to dig into the documentation a bit more and understand why :) http://python-docx.readthedocs.org/en/latest/user/text.html#apply-character-formatting
cell = row.cells[0]
cell.text = "text"
run = cell.paragraphs[0].runs[0]
run.font.bold = True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With