怎样把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 分钟前
【DeepAgent】概述
开发语言·数据库·python
书到用时方恨少!9 分钟前
Python multiprocessing 使用指南:突破 GIL 束缚的并行计算利器
开发语言·python·并行·多进程
Warson_L39 分钟前
Python 常用内置标准库
python
Warson_L1 小时前
Python 函数的艺术 (Functions)
python
Warson_L1 小时前
Python 流程控制与逻辑
后端·python
long_songs1 小时前
手柄键盘映射器【github链接见文末 】
python·游戏·计算机外设·pygame·软件推荐·手柄映射键盘
必然秃头1 小时前
Python 环境安装及项目构建指南
python
Warson_L1 小时前
Python 四大组合数据类型 (Collection Types)
后端·python
廋到被风吹走1 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
Warson_L1 小时前
Python 数据类型核心笔记
python