设置表格对齐方式和设置单元格大小

from  docx  import  Document
from docx.shared  import Cm
from  docx.enum.table  import  WD_TABLE_ALIGNMENT

#设置表格对齐方式
w=Document(r'D:word练习练习.docx')
table=w.tables[0]
table.alignment=WD_TABLE_ALIGNMENT.LEFT    #左对齐


#设置表格宽度
for  col  in  table.columns:
    for  cell in col.cells:
        cell.width=Cm(3)

#设置表格高度
for  row  in  table.rows:
    for  cell in  row.cells:
        cell.height=Cm(3)

w.save(r'D:word练习练习_1.docx')
原文地址:https://www.cnblogs.com/luckiness/p/13255627.html