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_ids[page])

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)

相关推荐
databook5 分钟前
让数学公式自动推导
python·数学·动效
m0_7335654618 分钟前
如何指定PHP版本运行phpMyAdmin_多版本共存配置
jvm·数据库·python
love530love41 分钟前
ComfyUI MediaPipe 猴子补丁终极完善版:补全上下文管理与姿态检测兼容
人工智能·windows·python·comfyui·protobuf·mediapipe
小小编程路1 小时前
新手快速学 Python 极简速成指南
开发语言·c++·python
小马过河R1 小时前
RAG检索优化策略:系统性四层框架解析
人工智能·python·算法·ai·llm·rag·问答
yzx9910131 小时前
脚本定制从入门到实践:打造你的专属浏览器助手
python
AI技术控1 小时前
论文解读:AE-TCN-SA——基于自编码器、TCN 与自注意力机制的锂电池内短路诊断方法
人工智能·python·深度学习·算法·机器学习·自然语言处理
向日的葵0061 小时前
阿里云OSS从0到1实战:为宠物收养系统打造图片上传功能
python·阿里云·云计算·pillow·fastapi·宠物
川冰ICE2 小时前
Python爬虫实战⑳|Pandas时间序列,趋势分析一网打尽
爬虫·python·pandas
金融大 k2 小时前
多市场行情时间戳对齐:UTC 存储的夏令时陷阱与数据库设计方案
python·websocket·行情数据