Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold a table cells

I have following code:

table = document.add_table(rows=1, cols=8)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Name'
hdr_cells[1].text = 'Surname'
hdr_cells[2].text = 'Telephone'
(...)

Is it possible to make this cells bolded? Something like that:

hdr_cells[0].text = 'Name'
hdr_cells[1].text = 'Surname'
hdr_cells[2].text = 'Telephone'
hdr_cells[0].text.bold = True
hdr_cells[1].text.bold = True
hdr_cells[2].text.bold = True
like image 597
Sharpowski Avatar asked Feb 13 '23 23:02

Sharpowski


1 Answers

This should do the trick in this particular case:

hdr_cells[0].paragraphs[0].add_run('Name').bold = True

Or, more step-by-step:

col_names = ('Name', 'Surname', 'Telephone')
table = document.add_table(rows=1, cols=len(col_names))
hdr_cells = table.rows[0].cells
for idx, name in enumerate(col_names):
    paragraph = hdr_cells[idx].paragraphs[0]
    run = paragraph.add_run(name)
    run.bold = True
like image 158
scanny Avatar answered Mar 05 '23 22:03

scanny