怎样把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 分钟前
Python操作PDF页面详解:删除指定页的完整方案
开发语言·python·pdf
serve the people6 分钟前
python环境搭建 (十三) tenacity重试库
服务器·python·php
ASS-ASH6 分钟前
AI时代之向量数据库概览
数据库·人工智能·python·llm·embedding·向量数据库·vlm
乔江seven37 分钟前
【Flask 进阶】3 从同步到异步:基于 Redis 任务队列解决 API 高并发与长耗时任务阻塞
redis·python·flask
pchaoda1 小时前
基本面因子计算入门
python·matplotlib·量化
Wpa.wk1 小时前
接口自动化测试 - 请求构造和响应断言 -Rest-assure
开发语言·python·测试工具·接口自动化
岱宗夫up1 小时前
机器学习:标准化流模型(NF)
人工智能·python·机器学习·生成对抗网络
狂奔蜗牛飙车1 小时前
Python学习之路-循环语句学习详解
python·学习·python学习·#python学习笔记·循环语句详解
花月mmc1 小时前
CanMV K230 波形识别——整体部署(4)
人工智能·python·嵌入式硬件·深度学习·信号处理
lang201509281 小时前
Java WebSocket API:JSR-356详解
java·python·websocket