Python 处理 PPT 文件:读取、遍历、修改
Python 中可以使用第三方库 'python-pptx' 来处理 .ppt 文件。
安装 'python-pptx' 库:
pip install python-pptx
读取 .ppt 文件:
from pptx import Presentation
prs = Presentation('example.ppt')
遍历 .ppt 文件中的每一页:
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
print(shape.text)
修改 .ppt 文件中的内容:
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
shape.text = 'Hello World'
prs.save('example_modified.ppt')
原文地址: https://www.cveoy.top/t/topic/oRl3 著作权归作者所有。请勿转载和采集!