python-pptx解析pptx模板

from pptx import Presentation

from pptx.slide import Slide

from pptx.slide import NotesSlide

from pptx.text.text import TextFrame

from pptx.shapes.shapetree import SlideShapes

from pptx.shapes.placeholder import SlidePlaceholder

import json

path = "C:/luo/tmp/tmpl/009999.pptx"

prs = Presentation(path)

def res(obj) -> Slide:

return obj

def res2(obj) -> NotesSlide:

return obj

def res3(obj) -> SlideShapes:

return obj

def res4(obj) -> TextFrame:

return obj

def res5(obj) -> SlidePlaceholder:

return obj

page_ids = {i + 1: slide.slide_id for i, slide in enumerate(prs.slides)}

print(page_ids)

for page in page_ids:

slide = prs.slides.get(page_idspage)

slide = res(slide)

shapes = res3(slide.shapes)

for shape in shapes:

shape_text = ""

if shape.has_text_frame:

shape_text = shape.text

shape.text = ''

print("page: " + str(page) + ", idx: " + str(shape.placeholder_format.idx) + "," + str(shape_text))

获取 note

if slide.has_notes_slide and len(str(slide.notes_slide.notes_text_frame.text).strip()) > 0:

notes_slide = res2(slide.notes_slide)

tf = res4(notes_slide.notes_text_frame)

note_json = json.loads(tf.text)

for jn in note_json:

print(jn'name')

tf.text = '' # 用于 prs.save(path) 做清除 note

output = "C:/luo/tmp/tmpl/009999-gen-report.pptx"

prs.save(output)

相关推荐
Thanks_ks7 小时前
提示词工程实战:用结构化提示词让大模型输出稳定可控
python·大模型·json·openai·提示词工程·deepseek·系统提示词
BK贝壳9 小时前
布尔数组也能做按位取反、移位和乘法:bool-hybrid-array 的位运算在本机跑了一遍
开发语言·数据结构·python·性能优化·numpy
ZhengEnCi9 小时前
前端日志和后端日志怎么记:分级、JSON 格式、按天分文件与保留策略
前端·后端·python
用户03321266636713 小时前
使用 Python 为 PDF 文件添加页眉页脚
python
xurileidian13 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
郝学胜-神的一滴14 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy
神一样的老师16 小时前
WS63 BLE 配网实战:用 Python 在 PC 上替代手机完成 WiFi 配网
开发语言·python·智能手机
AI创界者16 小时前
2026 全平台 AI 视频换脸工作流实战:一套方案打通 N 卡、A 卡、I 卡与 Win / Mac
人工智能·python·aigc·音视频
DanCheng-studio17 小时前
计科毕设创新的选题思路
python·毕业设计·毕设
geovindu17 小时前
python: Decision Tree
开发语言·后端·python·决策树