怎样把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)
相关推荐
名字还没想好☜22 分钟前
Python 字符编码实战:encode/decode、UnicodeDecodeError 与 open 的 encoding 坑
开发语言·后端·python·编程语言
带多刺的玫瑰32 分钟前
Leecode#29刷题之两数相除
java·python·算法
smj2302_7968265233 分钟前
解决leetcode第4017题数组中的峰值II
python·算法·leetcode
卷无止境38 分钟前
AI Agent编程中,重构节奏与安全检查的门道
后端·python
慧都小妮子44 分钟前
用 Python 批量把 PDF 参考文献排成 MLA 格式:Spire.Doc for Python 实战
python·pdf·c#·spire.doc·mla格式·参考文献排版·pdf批量处理
卷无止境1 小时前
AI编程时代,代码复杂性正在悄悄失控
后端·python
开源量化GO1 小时前
看到“2026年 Python 与 API”时,用示例和拆解看清关系
人工智能·python
高洁011 小时前
大模型是怎么“学会“的:预训练、微调、对齐三段论
python·深度学习·transformer·知识图谱·tornado
529宝宝起名网1 小时前
用 Python 开发名字五行八字匹配工具:从八字排盘到喜用神起名的全流程实现
python
砚底藏山河1 小时前
并发与限频工程:把20只的2秒压到0.5秒不封号(魔码量化实战 #03)
java·开发语言·数据库·python·金融