直接上代码😁
from pptx import Presentation# 给定ppt文件所在的路径filepath = r"E:\flask_study\static\filePPT\shixi.pptx"pptx = Presentation(filepath)# 遍历ppt文件的所有幻灯片页for slide in pptx.slides:# 对单页ppt内容按从上到下排序,如果top相同则按从左到右排序sortedShapes = sorted(slide.shapes, key=lambda x: (x.top,x.left))# 遍历幻灯片页的所有形状for shape in sortedShapes:# print(str(shape.top)+""+str(shape.left))# 判断形状是否含有文本框,如果含有则顺序运行代码if shape.has_text_frame:# 获取文本框text_frame = shape.text_frame# 遍历文本框中的所有段落for paragraph in text_frame.paragraphs:# 输出文本框中的段落文字print(paragraph.text)