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)

相关推荐
成功人chen某2 小时前
配置VScodePython环境Python was not found;
开发语言·python
2301_786964362 小时前
EXCEL Python 实现绘制柱状线型组合图和树状图(包含数据透视表)
python·microsoft·excel
skd89993 小时前
小蜗牛拨号助手用户使用手册
python
「QT(C++)开发工程师」3 小时前
STM32 | FreeRTOS 递归信号量
python·stm32·嵌入式硬件
史迪仔01123 小时前
[python] Python单例模式:__new__与线程安全解析
开发语言·python·单例模式
胡耀超3 小时前
18.自动化生成知识图谱的多维度质量评估方法论
人工智能·python·自动化·知识图谱·数据科学·逻辑学·质量评估
三块钱07943 小时前
【原创】基于视觉大模型gemma-3-4b实现短视频自动识别内容并生成解说文案
开发语言·python·音视频
神码小Z3 小时前
Ubuntu快速安装Python3.11及多版本管理
python
JOYUAGV4 小时前
Word压缩解决方案
python·word
mahuifa4 小时前
(9)python开发经验
python·开发经验