pip install python-pptx
例子1:
from pptx import Presentation
prs = Presentation()
slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
title.text = "Hello, PowerPoint!"
prs.save('test.pptx')
例子2:
from pptx import Presentation
prs = Presentation('example.pptx')
for slide in prs.slides:
for shape in slide.shapes:
if hasattr(shape, "text"):
print(shape.text)