怎样把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)
相关推荐
用户8356290780512 小时前
使用 Python 在 Excel 中添加和自定义文本框
后端·python
总裁余(余登武)2 小时前
python多个py文件打包【解决exe不能移动运行bug】
python
kisloy3 小时前
【python零基础教程第24讲】代码规范与质量管控
开发语言·python
xywww1683 小时前
AWS 账号权限怎么分:根用户和 IAM 用户区别及日常使用建议
大数据·开发语言·人工智能·python·gpt·云计算·aws
许彰午5 小时前
100_Python面试常见问题汇总
java·python·面试
皓悦编程记5 小时前
【YOLO26 系列】基于YOLO26的垃圾分类检测系统【python源码+Pyqt5界面/WEB+数据集+训练代码】
python·qt·分类
滴滴滴嘟嘟嘟.5 小时前
强化学习消融实验-batch_size / clip_range / gae_lambda / lr
python·机器学习
2601_963932985 小时前
怀孕四个月能做流产吗?中期妊娠终止方式与子宫修护科普指南
python
zhr_math_king5 小时前
LangGraph-快速入门-第一个例子
python·langchain
爱吃苹果的梨叔6 小时前
2026年指挥中心分布式坐席怎么选?清虹创智让多系统、多坐席和大屏真正协同
python