给word中的表格增加行或者列-Python-小翔博客

from  docx  import  Document
from  docx.shared  import Cm
w=Document(r'  ')
w.tables[0].add_row()             #给表格增加一行
w.tables[0].add_column(Cm(5))     #给表格增加一列

print(len(w.tables[0].rows))      #查询表格中的行数
print(len(w.tables[0].columns))    #查询表格中的列数

row=w.tables[0].rows[1]       #定位表格的行
col=w.tables[0].columns[1]    #定位表格的列

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注