python word 删除表格的指定列

from docx import Document
from docx.shared import Cm


def delete_columns(path, table_n, column_n):
"""
删除一列
:param path: 路径
:param table_n: 第几个表格
:param column_n: 第几列
:return:
"""
doc = Document(path)
print(doc)
# 定位表格
print(doc.tables[table_n])
table = doc.tables[table_n]

column = table.columns[column_n]
for cell in column.cells:
cell._element.getparent().remove(cell._element)
doc.save(path)


path = r'''cc.docx'''

delete_columns(path, 0, 2)
posted @ 2024-02-01 16:55  郭峰g  阅读(131)  评论(0编辑  收藏  举报