怎样把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 小时前
Pelco KBD300A 模拟器:03.Pelco-P 协议 8 字节完整拆解 + 与 Pelco-D 一一对应终极对照表
python·测试工具·运维开发
R.lin2 小时前
Java 8日期时间API完全指南
java·开发语言·python
西南胶带の池上桜2 小时前
1.Pytorch模型应用(线性与非线性预测)
人工智能·pytorch·python
丘狸尾3 小时前
gradio uv无法add
开发语言·python
全栈陈序员4 小时前
【Python】基础语法入门(十七)——文件操作与数据持久化:安全读写本地数据
开发语言·人工智能·python·学习
爱笑的眼睛114 小时前
FastAPI 路由系统深度探索:超越基础 CRUD 的高级模式与架构实践
java·人工智能·python·ai
越甲八千5 小时前
uvicorn是啥
python
Dxy12393102165 小时前
Python字符串处理全攻略
开发语言·python
Fiona-Dong5 小时前
Louvain 算法
python·算法
坐吃山猪6 小时前
BrowserUse14-源码-ScreenShot模块-整理
linux·数据库·python