怎样把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)
相关推荐
weixin_447443256 分钟前
AI启蒙Lean4
python·c#
Ulyanov8 分钟前
雷达电子战仿真通信需求与Python实现挑战
python·数据通信·系统仿真·雷达电子对抗仿真
断眉的派大星29 分钟前
工厂模式(Factory Pattern)完整详解
python·设计模式
好家伙VCC30 分钟前
**基于RISC-V架构的嵌入式系统开发:从零开始构建高效低功耗应用**在当前物联网(IoT)和边缘计
java·python·物联网·架构·risc-v
大佬王1 小时前
WebSocket 连接池生产级实现:实时行情高可用与负载均衡
python·架构
ronindong1 小时前
Cursor 插件分享 | md-couture:一键将 Markdown 转换成带精美样式的 HTML
人工智能·python·ai编程
智慧地球(AI·Earth)1 小时前
规则引擎实战:Python中re库和pyknow库规则引擎实战教程
开发语言·python·程序人生
是小蟹呀^2 小时前
【总结】LangChain中的中间件Middleware
python·中间件·langchain·agent
qq_342295822 小时前
如何为容器内多个列表实现统一滚动条.txt
jvm·数据库·python
FreakStudio2 小时前
MicroPython对接大模型:uopenai + 火山方舟实现文字聊天和图片理解
python·单片机·ai·嵌入式·面向对象·电子diy