Python之ppt内容获取

import os
from pptx import Presentation as pra

#实例化ppt对象
pts1=pra(r"C:\Users\ppt\35595591.pptx")

results=[]
for slide in pts1.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            for paragraph in shape.text_frame.paragraphs:
                part=[]
                for run in paragraph.runs:
                    part.append(run.text)
                results.append(''.join(part))
results=[line for line in results if line.strip()]
#将结果写入txt文件中,注意编码问题
filet="C:/Users/2023/01Python/search.txt"
if os.path.exists(filet):
    os.remove(filet)
else:
    print("****")

f=open(filet,'w+',encoding='utf-8')
for i,p in enumerate(results):
    #print(i,p)
    f.write(p+'\n')
f.close()

你可能感兴趣的:(Python,python,powerpoint)