怎样把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)
相关推荐
小猴子爱上树28 分钟前
一站式解决图片视频翻译难题的高效AI工具
人工智能·python·音视频
weixin_5386019742 分钟前
智能体测开Day31
开发语言·python
lbb 小魔仙1 小时前
Git + Python 项目工作流最佳实践:pre-commit、CI、CHANGELOG 自动化
git·python·ci/cd
dyxal1 小时前
最长公共子序列(LCS)
python·算法
你驴我1 小时前
WhatsApp Cloud API 速率限制下的令牌桶与退避策略实践
网络·后端·python
AC赳赳老秦1 小时前
司法公开数据采集应用:OpenClaw 抓取裁判文书公开信息,批量整理同类参考案例
java·大数据·python·数据挖掘·数据分析·php·openclaw
小大宇2 小时前
Python 集成 Conda
开发语言·python·conda
初学者,亦行者3 小时前
利用Pyecharts绘制堆叠柱状图
python·信息可视化·数据分析
林泽毅3 小时前
PyTRIO:当强化学习不再需要本地GPU
人工智能·python·深度学习·机器学习
小陈phd3 小时前
QAnything 阅读优化策略05——检索
人工智能·python·机器学习