怎样把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)
相关推荐
Sakuraba Ema1 天前
从零理解 MoE(Mixture of Experts)混合专家:原理、数学、稀疏性、专家数量影响与手写 PyTorch 实现
人工智能·pytorch·python·深度学习·数学·llm·latex
嫂子的姐夫1 天前
041-全扣补环境:同花顺
爬虫·python·js逆向·逆向
2401_894241921 天前
机器学习与人工智能
jvm·数据库·python
vx-程序开发1 天前
springboot在线装修管理系统-计算机毕业设计源码56278
java·c语言·spring boot·python·spring·django·php
进击的雷神1 天前
主办方过滤、展位号模糊提取、多层级官网爬取、缅文编码解码——缅甸塑料展爬虫四大技术难关攻克纪实
网络·爬虫·python
winfredzhang1 天前
用 Python + DeepSeek AI 构建文件批量重命名与智能管理工具
python·api·重命名·预览·解压·deepseek
西西弗Sisyphus1 天前
Python 中__pycache__文件夹
python
qingcyb1 天前
重复 id 对应的多个对象
开发语言·python
mingshili1 天前
[python] asyncio常规操作记录
python·async
chushiyunen1 天前
python edge-tts实现tts文本转语音、音频
数据库·python·音视频