The code snippet below basically creates a table with the required number of rows and columns in a new word document i.e 2 columns and 14 rows. It then adds the content to the rows and columns accordingly.
from docx import Document
newDoc=Document()
newDoc.add_heading ('GIS Request Form')
newDoc.add_paragraph()
#inserting a table and the header and value objects to the 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 into table cells
for i in range(0,14):
row=table.rows[i]
row.cells[0].text=reqdheaderList[i]
row.cells[1].text=reqdvalueList[i]
I have been trying to make the contents of everything in column 1 bold, but it is not working.
#inserting contents into table cells
for i 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?