怎样把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)
相关推荐
一见5 分钟前
如何安装 dlib 和 OpenCV(不带 Python 绑定)
人工智能·python·opencv
刘晓倩36 分钟前
Python内置函数-hasattr()
前端·javascript·python
逆境清醒38 分钟前
Python中的常量
开发语言·python·青少年编程
紫小米1 小时前
MCP协议与实践
python·llm·mcp协议
二哈喇子!1 小时前
Python报错:SyntaxError: invalid character ‘,‘ (U+FF0C)
python
走遍西兰花.jpg1 小时前
hive如何使用python脚本
数据仓库·hive·hadoop·python
小镇学者1 小时前
【python】python有必要像go或者nodejs那样做多版本切换吗?
开发语言·python·golang
2501_919219042 小时前
画册设计尺寸在不同设备(手机/平板)显示差异如何处理?
python·智能手机·电脑
子午2 小时前
【2026原创】眼底眼疾识别系统~Python+深度学习+人工智能+CNN卷积神经网络算法+图像识别
人工智能·python·深度学习
ACERT3332 小时前
10.吴恩达机器学习——无监督学习01聚类与异常检测算法
python·算法·机器学习