python-docx|让列表元素居中

2019-01-02  本文已影响0人  reallocing

使用库python-docx


from docx.enum.tableimport WD_TABLE_ALIGNMEN

table = doc.add_table(rows=rows,cols=cols,style='Table Grid')

hdr_cells = table.rows[0].cells

hdr_cells[0].text =u'标题1'

hdr_cells[1].text =u'标题2'

hdr_cells[2].text =u'标题3'

## 首行居中

for i in range(cols):

    hdr_cells[i].paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER

上一篇 下一篇

猜你喜欢

热点阅读