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)

相关推荐
xiangjiaodalishi11 小时前
主流 AI 爬虫 User-Agent 清单大全:分组、配置与持续维护(2026 版)
人工智能·爬虫·python
普贤莲花11 小时前
先学Workbuddy还是“人工智能训练师”,或者python基础课?
开发语言·人工智能·python
砚底藏山河11 小时前
python量化实操:回测数据缓存与重放
java·python·金融·1024程序员节
第404号工位12 小时前
浏览器的“无痕模式”是当代最大安慰剂?我用 30 行 JS 提取硬件指纹,跨网络换代理照样精准锁定你
linux·人工智能·python
凌界天行12 小时前
知名的无人机侦测肩灯制造厂名声
python
XZ-07000112 小时前
week10-直方图
python
外收内放12 小时前
FastAPI猜字谜实战(6):日志与异常
开发语言·python·学习·fastapi
PythonFun12 小时前
如何生成Python50天系列学习互动网页课件
python·wps
垆边人似月.12 小时前
预处理与参数调优(让识别率从“能看”到“可用”)
开发语言·python·自然语言处理
gf132111112 小时前
python_高德地图驾车时长查询
数据库·python·mysql