怎样把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)
相关推荐
L@ncor2 分钟前
第二章可能出现的问题
人工智能·python
y = xⁿ10 分钟前
大模型基础概念
python
ctlover26 分钟前
排序与查找算法详解
开发语言·python
用户83562907805128 分钟前
如何使用 Python 给 Word 文档添加水印
后端·python
泡干脆面就番茄44 分钟前
深度学习:PyTorch框架初识——MNIST手写数字识别
python·深度学习
shirsl1 小时前
算法 Day 5 树 / 二叉树 + DFS
数据结构·python·算法
门思科技1 小时前
开源网关有哪些:主流类型梳理
网络·python·物联网
szephyr1 小时前
Python 爬虫合规与反爬实战:从 requests 到 Playwright
爬虫·python·requests·playwright·反爬
E-iceblue1 小时前
Excel 列转行/行列转换全指南:从 4 种常见解法到 Python 批量自动化
python·excel·python库·spire.xls
言乐61 小时前
Python + NumPy 从零实现的 BP 神经网络(反向传播)脚本模型,包含前向传播、反向传播、训练和预测,并用 XOR 数据做示例
python·django·virtualenv·pygame·tornado