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


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')

 

相关内容

    暂无相关文章

评论关闭