怎样把pptx课件转换成word文档

如果你还没有安装python-pptxpython-docx,请先运行以下命令:

pip install python-pptx python-docx

python 复制代码
from pptx import Presentation
from docx import Document
import re

# 函数:清理文本,移除特殊字符和控制字符
def clean_text(text):
    # 移除所有控制字符和特殊字符
    cleaned_text = re.sub(r'[\x00-\x1F\x7F-\x9F]', '', text)
    return cleaned_text

# 读取PPT文件
ppt_file = 'example.pptx'
presentation = Presentation(ppt_file)

# 创建Word文档
doc = Document()

for slide in presentation.slides:
    for shape in slide.shapes:
        if hasattr(shape, "text"):
            # 清理文本内容
            cleaned_text = clean_text(shape.text)
            doc.add_paragraph(cleaned_text)

# 保存Word文档
doc_file = 'example.docx'
doc.save(doc_file)
相关推荐
三十岁老牛再出发7 小时前
08.18每日总结
c++·python·numpy·pandas
️学习的小王7 小时前
Anaconda国内镜像配置与conda常用命令
ide·经验分享·python·conda
Zane19947 小时前
daemon 线程说没就没?一文讲透 threading 的适用场景与线程安全
后端·python
up up day7 小时前
Python enchant 模块使用教程
python
zoujiahui_20187 小时前
Python 包与环境管理工具 uv
开发语言·python·uv
程序猿阿森8 小时前
Python 闭包与装饰器:从入门到精通
开发语言·python·面试
老大白菜8 小时前
Qwen3.8-27B 本地推理 + DeepSeek Harness 配置
python·qwen·deepseek·harness
Code额9 小时前
Python 连接 DeepSeek API,OpenAI 对话方式总结
后端·python·ai·ai编程
电化学仪器白超9 小时前
MV-CS200-10UC相机参数配置
python·单片机·嵌入式硬件·数码相机·自动化·ltspice
荣码9 小时前
向量数据库选型:4种方案全测了,选错重来成本最高
java·python