怎样把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)
相关推荐
C137的本贾尼8 小时前
MCP 完全指南:从零开始掌握模型上下文协议
人工智能·python
威联通安全存储9 小时前
SMT表面贴装线AOI检测网中TS-h2287XU-RP混合架构的物理部署
python·架构
大鱼>9 小时前
Scikit-learn Pipeline:构建可复用的 ML 流水线
python·机器学习·scikit-learn
闲猫9 小时前
深入理解 Skills:从 API 调用到智能体行为封装
人工智能·python·langchain
还是鼠鼠9 小时前
AI掘金头条新闻系统 (Toutiao News)-缓存相关推荐新闻
后端·python·mysql·fastapi·web
骑士雄师9 小时前
大模型:runnable
python·embedding
2401_868534789 小时前
系统分析师案例分析题常考知识点
python·计算机网络
江华森10 小时前
Python 实现 2048 游戏(三):面向对象重构与AI模拟
python
可以飞的话10 小时前
五、数据处理1
python
鱼毓屿御10 小时前
Python 装饰器与函数调用机制(复习笔记 · 2026-07-07)
开发语言·python