python docx API 之 Table

Table API

参考:https://python-docx.readthedocs.io/en/latest/api/table.html

1. Table对象

#1.创建table
document.add_table()
#2.在右侧新增列
add_column(width)
#3.在底部新增行
add_row()
#4.设置表格的对齐方式,值为枚举类型 WD_TABLE_ALIGNMENT
alignment
#5.设置表格自动列宽
autofit
#6.访问单元格
cell(row_idx, col_idx)
#7.访问指定的列
column_cells(column_idx)
#8.返回列的列表
columns
#9.访问指定的行
row_cells(row_idx)
#10.返回行的列表
rows
#11.表格风格
style
#12.表格方向,结果为枚举值  WD_TABLE_DIRECTION
table_direction

2. Cell对象

#1.增加内容
add_paragraph(text=u'', style=None)
#2.表格嵌套
add_table(rows, cols)
#3.合并单元格,当前单元格和other_cell组成的矩形区域合并
merge(other_cell)
#4.访问段落
paragraphs
#5.访问表格
tables
#6.访问或指定内容
text
#7.设置表格内容垂直对齐,值为枚举型 WD_CELL_VERTICAL_ALIGNMENT
vertical_alignment
#8.设置行宽
width

3. Row对象

#1.返回行内的单元格列表
cells
#2.访问或设置行高
height
#3.访问或设置行高,枚举类型
height_rule
#4.返回行所属的表格
table

4. Column对象

#1.返回列内单元格列表
cells
#2.返回列所属的表格
table
#3.访问或设置列宽
width

5.Rows和Columns对象

#1.返回row和column对象集合,支持迭代,切片,索引访问
#2.返回集合所属的table对象
table

posted on 2022-05-24 14:36  朝朝暮Mu  阅读(693)  评论(0)    收藏  举报