1、读取PPT
python
import pptx
ppt=pptx.Presentation(r'C:\Users\user\Documents\\2.pptx')
# ppt.save(r'C:\Users\user\Documents\\1.pptx')
# slide=ppt.slides.add_slide(ppt.slide_layouts[1])
# 读取所有幻灯片上的文字
for slide in ppt.slides:
for shape in slide.shapes:
if shape.has_text_frame:
text_box=shape.text_frame
for para in text_box.paragraphs:
print(para.text)
print("over")
2、写入PPT
python
import pptx
# 创建一个新的PPT文件
prs = pptx.Presentation()
# 添加标题幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[0])
title = slide.shapes.title
title.text = "My PPT File"
# 添加带有段落的幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[1])
left_shape = slide.shapes.placeholders[1]
left_shape.text = "This is a paragraph."
prs.save("example.pptx")