怎样把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)
相关推荐
金銀銅鐵34 分钟前
[Python] 用 turtle 来绘制瑞典国旗
python
Albert Edison35 分钟前
【GUI 自动化测试】Pywinauto 常见操作
自动化测试·python·pywinauto
海兰36 分钟前
【高速缓存】RedisVL为文本生成嵌入向量实践指南
人工智能·python·机器学习
2601_9557600744 分钟前
如何用 Claude Opus 5 API 批量扩展长尾关键词和文章选题
前端·python·搜索引擎
艾斯特_1 小时前
从模型调用到可用聊天应用:会话状态与消息协议
python·ai·aigc
Marst Code1 小时前
Python 3.9 已停止维护!从 3.9 到 3.14 全版本深度对比,生产环境该选哪个?
开发语言·python
llwszx1 小时前
【Java/Go后端手撸原生Agent(第九篇):Plan-and-Execute规划模式——从“走一步看一步“到“先谋后动“】
java·python·golang·agent开发·plan模式·规划执行模式
lxw18449125142 小时前
Python uv 完整使用教程
python·conda·pip·uv
hangyuekejiGEO2 小时前
临沂GEO技术解析与行业应用方案
人工智能·python
不做Java程序猿好多年3 小时前
Java中 String、StringBuffer、StringBuilder 的区别详解
开发语言·python