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)
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐