怎样把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)
相关推荐
倦王2 分钟前
力扣日刷47-补
python·算法·leetcode
2501_9216494922 分钟前
原油期货量化策略开发:历史 K 线获取、RSI、MACD 布林带计算到多指标共振策略回测
后端·python·金融·数据分析·restful
真心喜欢你吖26 分钟前
统信操作系统UOS部署安装OpenClaw+飞书接入完整教程(国产大模型配置)
人工智能·python·语言模型·大模型·openclaw·小龙虾
用户83562907805134 分钟前
使用 Python 自动生成 Excel 柱状图的完整指南
后端·python
xcbrand35 分钟前
口碑好的品牌策划厂家
大数据·人工智能·python
liu****1 小时前
LangChain-AI应用开发框架(七)
人工智能·python·langchain·大模型应用·本地部署大模型
hhcgchpspk1 小时前
网速上传下载流量监测工具尝试
网络·python·cmd·psutil
飞Link1 小时前
大模型时代的“语言编程”:Prompt Engineering (提示词工程) 深度解析与实战指南
开发语言·python·prompt
郝学胜-神的一滴1 小时前
Socket实战:从单端聊天到多用户连接的实现秘籍
服务器·开发语言·python·网络协议·pycharm
zzwq.1 小时前
线程池与进程池:concurrent.futures高效并发
python