Making cells bold in a table using python-docx -
the code snippet below creates table required number of rows , columns in new word document i.e 2 columns , 14 rows. adds content rows , columns accordingly.
from docx import document newdoc=document() newdoc.add_heading ('gis request form') newdoc.add_paragraph() #inserting table , header , value objects table table=newdoc.add_table(rows=14,cols=2) table.style='table grid' table.autofit=false table.columns[0].width=2500000 table.columns[1].width=3500000 #inserting contents table cells in range(0,14): row=table.rows[i] row.cells[0].text=reqdheaderlist[i] row.cells[1].text=reqdvaluelist[i]
i have been trying make contents of in column 1 bold, not working.
#inserting contents table cells in range(0,14): row=table.rows[i] row.cells[0].text=reqdheaderlist[i] row.cells[0].paragraphs[0].add_run(line[0]).bold=true row.cells[1].text=reqdvaluelist[i]
help?
you can achieve using following loop:
bolding_columns = [0] row in list(range(14)): column in bolding_columns: table.rows[row].cells[column].paragraphs[0].runs[0].font.bold = true
Comments
Post a Comment