python-pptx 学习笔记 Tables

Tables API

#1.添加表格
#add_table方法得到shape对象,而不是table本身
from pptx import Presentation
from pptx.util import Inches
# ---create presentation with 1 slide---
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
# ---add table to slide---
x, y, cx, cy = Inches(2), Inches(2), Inches(4), Inches(1.5)
shape = slide.shapes.add_table(3, 3, x, y, cx, cy)
shape
<pptx.shapes.graphfrm.GraphicFrame object at 0x1022816d0>、
#判断是否是表格
shape.has_table
True
table = shape.table
#2.访问单元格
#通过行列访问
cell = table.cell(0, 0)
cell.text
#3.合并单元格
cell = table.cell(0, 0)
other_cell = table.cell(1, 1)
cell.is_merge_origin
#False
cell.merge(other_cell)
cell.is_merge_origin
#True
cell.is_spanned
#False
other_cell.is_spanned
#True
table.cell(0, 1).is_spanned
#True
#4.取消合并单元格
cell = table.cell(0, 0)
cell.is_merge_origin
#True
cell.split()
cell.is_merge_origin
#False
table.cell(0, 1).is_spanned
#False

posted on   朝朝暮Mu  阅读(367)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示