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)

相关推荐
三十岁老牛再出发8 小时前
08.18每日总结
c++·python·numpy·pandas
Zane19948 小时前
daemon 线程说没就没?一文讲透 threading 的适用场景与线程安全
后端·python
up up day8 小时前
Python enchant 模块使用教程
python
zoujiahui_20188 小时前
Python 包与环境管理工具 uv
开发语言·python·uv
程序猿阿森9 小时前
Python 闭包与装饰器:从入门到精通
开发语言·python·面试
老大白菜9 小时前
Qwen3.8-27B 本地推理 + DeepSeek Harness 配置
python·qwen·deepseek·harness
Code额10 小时前
Python 连接 DeepSeek API,OpenAI 对话方式总结
后端·python·ai·ai编程
电化学仪器白超10 小时前
MV-CS200-10UC相机参数配置
python·单片机·嵌入式硬件·数码相机·自动化·ltspice
荣码10 小时前
向量数据库选型:4种方案全测了,选错重来成本最高
java·python
eagle_Annie10 小时前
Python/torch/深度学习——Miniforge+uv环境安装
python·深度学习·uv