删除表格的行或者列

from  docx  import  Document
w=Document(r'F:\word练习\表格.docx')
table_1=w.tables[0]

#删除行
print(len(table_1.rows))
row2=table_1.rows[1]
row2._element.getparent().remove(row2._element)
print(len(table_1.rows))

#删除列
col=table_1.table.columns[1]
for  cell in  col.cells:
    cell._element.getparent().remove(cell._element)
w.save(r'F:\word练习\删除表格的行或者列.docx')

 

posted @ 2020-07-04 22:34  马蹄哒哒  阅读(375)  评论(0编辑  收藏  举报