怎样把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)
相关推荐
码界筑梦坊7 分钟前
125-基于Flask的客户购物偏好数据可视化分析系统
python·信息可视化·flask·毕业设计
测试秃头怪21 分钟前
接口测试与常用接口测试工具详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
坐吃山猪22 分钟前
【Nanobot】README03_LEVEL2_工具系统架构
python·源码·agent·nanobot
河阿里30 分钟前
Python容器:特性、区别和使用场景
开发语言·python
AC赳赳老秦32 分钟前
OpenClaw与思维导图工具联动:自动生成工作规划脑图、拆解任务节点,适配职场管理
java·大数据·服务器·数据库·python·php·openclaw
才兄说33 分钟前
机器人二次开发机器人动作定制?数据优化迁移
python
情绪总是阴雨天~1 小时前
深入理解A2A协议:从零搭建多Agent协作系统实战
python·langchain·langgraph·a2a
yoyo_zzm1 小时前
四大编程技术对比:PHP、Java、Python与HTML
java·python·php
C137的本贾尼1 小时前
融会贯通:打造完整的 RAG 问答链
python·langchain
deephub1 小时前
构建一个可自我改进的多 Agent RAG 系统:架构、评估,以及带人工审核的 Prompt 反馈闭环
人工智能·python·大语言模型·rag