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)

相关推荐
天l志3 分钟前
Chrome Extension + 本地服务:浏览器页面上下文采集与远程执行技术设计
python·谷歌浏览器
CodexDave5 分钟前
Python 自动化接单实战(九):Windows 免环境交付如何打包与诊断
windows·python·自动化·python自动化·pyinstaller·软件交付·windows打包
CTA量化套保8 分钟前
2026年量化入门路线,概念规则和简单实现逐步走
人工智能·python
米码收割机12 分钟前
【Python】Python Django+Vue3校园自习室预约管理系统(源码+文档+PPT)【独一无二】
开发语言·python·django
AstartesEternal20 分钟前
python第二次作业(列表,字典)
开发语言·python
拉特莉的祈祷机22 分钟前
绿色测试日志为什么可能已经失效:用 AET 绑定命令与当前代码
python
三金1213837 分钟前
Python的一些内置模块
python
NPE~1 小时前
RAG 实战教程:从零构建企业智能问答 Agent
python·ai·实战·rag·agent搭建
BaoshengTT2 小时前
2026年双流区汽车贴膜种类及挑选要点保圣威固7V不凡门店
python
zhiSiBuYu05172 小时前
Flask 请求与响应新手实战指南
后端·python·flask