怎样把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)
相关推荐
才兄说9 分钟前
机器人二次开发机器人动作定制?动作迁移数据优化
python
用户83562907805125 分钟前
用 Python 实现 Excel 散点图绘制与定制
后端·python
PAK向日葵36 分钟前
从零实现 Python 虚拟机(一):PVM 基本原理介绍
python
神所夸赞的夏天41 分钟前
创建虚拟环境提示SSLError错误
python
极光代码工作室1 小时前
基于机器学习的二手商品价格预测系统
人工智能·python·深度学习·机器学习
无情的西瓜皮1 小时前
MCP协议实战:从零搭建一个AI Agent工具服务器
运维·服务器·python
IT策士1 小时前
Django 从 0 到 1 打造完整电商平台:系列总结 + 项目演示与后续扩展
后端·python·django
君为先-bey2 小时前
LeMiCa——基于扩散模型的高效视频生成的词典序最小化路径缓存
python·算法·机器学习·扩散模型
L_cl2 小时前
大模型应用开发 9.FastAPI ① 请求与响应
python·fastapi
treesforest3 小时前
机房IP是什么?有什么危害?如何识别?
网络·数据库·python·网络协议·tcp/ip·网络安全