怎样把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)
相关推荐
SilentSamsara11 分钟前
生成器完全指南:`yield` 与惰性求值的工程价值
linux·开发语言·python·算法·机器学习·青少年编程
YJlio8 小时前
7.4.5 Windows 11 企业网络连接与网络重置实战:远程访问、本地策略与故障恢复
前端·chrome·windows·python·edge·机器人·django
深耕AI8 小时前
【VS Code避坑指南】点击Python图标提示“没有Python环境”,选择安装uv后这堆输出到底是什么意思?
开发语言·python·uv
第一程序员8 小时前
Rust生命周期管理实战指南:从困惑到掌握
python·github
程序员威哥8 小时前
实战!Python爬京东商品评论:从采集到情感分析+词云可视化,新手30分钟跑通
开发语言·爬虫·python·scrapy
风噪8 小时前
centos7 python3.13全套安装(可用于离线复制)
python
小陈的进阶之路9 小时前
Python系列课(5)——数据容器
windows·python
知识领航员9 小时前
2026年推荐6个AI音乐工具
java·人工智能·python·eclipse·django·php·pygame
PieroPc9 小时前
证件裁切拼版工具
python
2401_833033629 小时前
golang如何实现MQTT主题通配符路由_golang MQTT主题通配符路由实现策略
jvm·数据库·python