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)

相关推荐
Want5952 分钟前
Python跳动的爱心②
开发语言·python·数学建模
田里的水稻5 分钟前
PyTorch_TensorBoard展示
人工智能·pytorch·python·深度学习·神经网络
张张123y24 分钟前
后端第九课:部署上线(把你的 FastAPI 后端真正跑起来给别人用)
python·docker·部署·fastapi
云勤通30 分钟前
智慧后勤系统哪家定制能力强
大数据·python
想七想八不如114081 小时前
元学习简单入门
人工智能·pytorch·python·深度学习·学习·机器学习
Zucker n1 小时前
一款适合研究生科研工作安排的日历
linux·数据库·python
尼给路达哟2 小时前
node(koa)和python(fastapi)面试
python·面试·fastapi
曲径海盗3 小时前
【Python 学习第 32 天】字符串基础
python·学习笔记·编程入门
田里的水稻3 小时前
PyTorch_torchvision---数据集下载\TensorBoard可视化
人工智能·pytorch·python·深度学习·机器学习
程序员正茂3 小时前
Win11使用自定义训练集训练ncnn模型
python·yolo·图像识别·移动端·ncnn