怎样把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)
相关推荐
清水白石0088 小时前
Python 纯函数编程:从理念到实战的完整指南
开发语言·python
twilight_4698 小时前
机器学习与模式识别——机器学习中的搜索算法
人工智能·python·机器学习
Jia ming8 小时前
《智能法官软件项目》—罪名初判模块
python·教学·案例·智能法官
Jia ming9 小时前
《智能法官软件项目》—法律文书生成模块
python·教学·案例·智能法官软件
曦月逸霜9 小时前
Python数据分析——个人笔记(持续更新中~)
python
海棠AI实验室9 小时前
第六章 从“能用”到“能交付”的关键一刀:偏好对齐(Preference Alignment)数据工程
python·私有模型训练
百锦再9 小时前
Java多线程编程全面解析:从原理到实战
java·开发语言·python·spring·kafka·tomcat·maven
Jia ming10 小时前
《智能法官软件项目》—法律计算器模块
python·教学·案例·智能法官
爱华晨宇10 小时前
Python列表入门:常用操作与避坑指南
开发语言·windows·python
一切顺势而行10 小时前
python 面向对象
开发语言·python