How can I make table header cells both bold and underline in python?

耗尽温柔 提交于 2020-01-24 01:52:10

问题


I am creating a table using python 3.4 and I would like to make the header both bold and underline. The following code will make the header bold:

table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Date Filmed:').bold = True
hdr_cells[2].paragraphs[0].add_run('Barcode Number:').bold = True

If I change the 3rd line to:

hdr_cells[0].paragraphs[0].add_run('Date Filmed:').underline = True

it will make the text underlined, but not bold. It there a way to make the text of the header both bold and underlined?


回答1:


You just need to add boolean run properties one at a time

run = hdr_cells[0].paragraphs[0].add_run('Date Filmed:')
run.bold = True
run.underline = True


来源:https://stackoverflow.com/questions/31797491/how-can-i-make-table-header-cells-both-bold-and-underline-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!