怎样把pptx课件转换成word文档

如果你还没有安装python-pptx和python-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)
相关推荐
虎虎(_ _)。゜zzZ1 小时前
关于字典中的解包问题
python
全栈弄潮儿²⁰²⁴1 小时前
Python实战第2期: 变量与数据类型
python·变量·数据类型·python实战
程序员yu2 小时前
会编网络:别被入门教程骗了,Python实用能力不在语法本身
开发语言·python·学习·算法
鬼手点金2 小时前
opencode组件详解-安装方式
人工智能·python·优化器·分析器·nanogpt
Bruce_Liuxiaowei2 小时前
Python 字典默认值完全指南:从 KeyError 到 defaultdict
开发语言·数据结构·python·字典
数据杂坛2 小时前
【Python程序开发系列】一文搞清楚Gunicorn以及和Nginx的区别
python·nginx·gunicorn
zjh9005302 小时前
Visual C++ 2010 安装使用完整包:高手秘籍
python
Allen_LVyingbo2 小时前
信息化部门在AI时代的编程转移路径分析(上)
人工智能·python·算法·健康医疗·数据库开发·时序数据库·数据库架构
用户0332126663672 小时前
Python 实现 Word/TXT 互转:附完整代码
python
常山云栈3 小时前
Anaconda和uv的区别是什么?
python·anaconda·uv