
python实现读取每一页PPT中的内容,将其写到word文档中
python实现读取每一页PPT中的内容,将其写到word文档中
·
from pptx import Presentation
from docx import Document
def ppt_to_word(ppt_file, word_file):
# 读取PPT文件
ppt = Presentation(ppt_file)
# 创建一个新的Word文档
doc = Document()
# 遍历PPT中的每一页
for slide in ppt.slides:
# 遍历幻灯片中的每一个形状
for shape in slide.shapes:
# 如果形状包含文本
if hasattr(shape, "text"):
# 将文本写入Word文档
doc.add_paragraph(shape.text)
# 保存Word文档
doc.save(word_file)
# 使用示例
ppt_file = "example.pptx"
word_file = "output.docx"
ppt_to_word(ppt_file, word_file)
更多推荐
所有评论(0)