怎样把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)
相关推荐
alphaTao8 小时前
LeetCode 每日一题 2026/5/18-2026/5/24
python·leetcode
徐安安_ye18 小时前
FlashAttention学习路线:从调API到写算子,你该走哪条路
python·学习
IT策士8 小时前
Django 从 0 到 1 打造完整电商平台:商品搜索
后端·python·django
茉莉玫瑰花茶8 小时前
LangGraph 持久化(Persistence)[ 2 ]
开发语言·python·ai·langgraph
有味道的男人8 小时前
AI 对接 1688 图搜接口|Open Claw 以图搜货实战
开发语言·python
MediaTea9 小时前
DL:Transformer 的基本原理与 PyTorch 实现
人工智能·pytorch·python·深度学习·transformer
wuxinyan1239 小时前
工业级大模型学习之路024:LangChain零基础入门教程(第七篇):RAG 系统评估、全链路调优
人工智能·python·学习·langchain
Kingairy9 小时前
Python简单算法题
开发语言·python
SilentSamsara9 小时前
日志与可观测性:logging 进阶配置与结构化日志实战
运维·开发语言·python·青少年编程
隔壁大炮9 小时前
MNE-Python 第7天学习笔记:事件相关电位(ERP)分析
python·eeg·mne·脑电数据处理