0.安装模块
window: pip install python-pptx
mac:pip3 install python-pptx
1.PPT结构
slide 幻灯片页
shape 形状
paragraph 段落
run 文字块
2.获取slide
.slides 得到一个列表,包含每个列表slide
from pptx import Presentation
ppt = Presentation("1.pptx")
for slide in ppt.slides:
print(slide)
2.获取形状
slide.shapes 形状
from pptx import Presentation
ppt = Presentation("1.pptx")
for slide in ppt.slides:
#print(slide)
for shape in slide.shapes:
print(shape)
ptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.group.GroupShape object at 0x0000016705B67080>
<pptx.shapes.placeholder.SlidePlaceholder object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.group.GroupShape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.group.GroupShape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.group.GroupShape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.group.GroupShape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.group.GroupShape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.connector.Connector object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.connector.Connector object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.group.GroupShape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.group.GroupShape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.group.GroupShape object at 0x0000016705B670F0>
<pptx.shapes.placeholder.SlidePlaceholder object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.group.GroupShape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.group.GroupShape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.picture.Picture object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.picture.Picture object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.group.GroupShape object at 0x0000016705B67390>
<pptx.shapes.autoshape.Shape object at 0x0000016705B670F0>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67080>
<pptx.shapes.autoshape.Shape object at 0x0000016705B67390>
<pptx.shapes.picture.Picture object at 0x0000016705B670F0>
3.判断shape内的文字,并进行输出
shape.has_text_frame 判断是否有文字
shape.text_frame 获取文字框
from pptx import Presentation
ppt = Presentation("1.pptx")
for slide in ppt.slides:
#print(slide)
for shape in slide.shapes:
if shape.has_text_frame:
text_frame = shape.text_frame
print(text_frame.text)
Reagent OS Developer test version
201910182024
2033hill_servie
应用
JesseGary
电话
短信
相机
Reagent 中心
设置
天气
相册
音乐
磁贴
天气
广东
11:24
应用
电话
短信
相机
Reagent 中心
商店
Chrome
设置
天气
相册
音乐
主题
便签
4.寻找paragra
from pptx import Presentation
ppt = Presentation("1.pptx")
for slide in ppt.slides: #> .slides 得到一个列表,包含每个列表slide
#print(slide)
for shape in slide.shapes: #> slide.shapes 形状
if shape.has_text_frame: #shape.has_text_frame 判断是否有文字
text_frame = shape.has_text_frame #shape.text_frame 获取文字框
#print(text_frame.text)
for paragraph in text_frame.paragraphs: #text_frame.paragraphs 获取段落
print(paragraph.text)
后续将会持续更新excel,ppt,爬虫,人工智能等相关内容,敬请关注