baodan/tmp/inspect_ppt_shapes.py

17 lines
674 B
Python

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE
def visit(shapes, depth=0):
for shape in shapes:
text = shape.text.strip().replace("\n", " | ") if getattr(shape, "has_text_frame", False) else ""
print(" " * depth, shape.name, shape.shape_type, round(shape.top / 914400, 2), round(shape.height / 914400, 2), repr(text[:180]))
if shape.shape_type == MSO_SHAPE_TYPE.GROUP:
visit(shape.shapes, depth + 1)
deck = Presentation(r"D:\work\code\python\coding\baodanagent\ppt_work\double_iul_template.pptx")
for index, slide in enumerate(deck.slides, start=1):
print("\nSLIDE", index)
visit(slide.shapes)