怎样把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)
相关推荐
小北方城市网6 分钟前
SpringBoot 集成 RabbitMQ 实战(消息队列解耦与削峰):实现高可靠异步通信
java·spring boot·python·微服务·rabbitmq·java-rabbitmq·数据库架构
百锦再7 分钟前
国产数据库现状与技术演进
数据库·python·plotly·flask·virtualenv·pygame·tornado
Piar1231sdafa11 分钟前
YOLO11-Seg与Fasternet-BiFPN结合的枣果实品质检测系统实现详解
python
minglie114 分钟前
micropython 按键
python
阿豪只会阿巴14 分钟前
项目心得——发布者和订阅者问题解决思路
linux·开发语言·笔记·python·ubuntu·ros2
chilavert31832 分钟前
技术演进中的开发沉思-317 JVM:指令集(下)
开发语言·python
tjjucheng1 小时前
小程序定制开发公司排名
python
27669582921 小时前
dy bd-ticket-guard-client-data bd-ticket-guard-ree-public-key 逆向
前端·javascript·python·abogus·bd-ticket·mstoken·ticket-guard
Maddie_Mo1 小时前
智能体设计模式 第一章:提示链
人工智能·python·语言模型·rag
m0_726365831 小时前
哈希分分预测系统 + Python Worker + Web 仪表盘”小系统(PHP + MySQL)
前端·python·哈希算法