怎样把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)
相关推荐
三川6988 小时前
Tkinter库的学习记录06-变量类别
python
wenying_443237448 小时前
Python脚本—1.提取压缩包中的pdf文件
python·ai编程
_Jimmy_9 小时前
SQLAlchemy 复杂 SQL 执行指南与模板库
python·sql
六个九十度9 小时前
用python脚本访问被网关隔离的嵌入式设备
开发语言·python
GEO_ai_zhijian9 小时前
饮料生产线质量检测系统供应商哪家强
大数据·python
量化吞吐机10 小时前
近期量化工具怎么选,先看规则流程能否承接
人工智能·python
一世繁华行10 小时前
Python帧对象
python
三川69811 小时前
Tkinter库的学习记录08- 容器控件
python
c_lb728811 小时前
近期AI量化工具选择,学习开发执行要分开
人工智能·python
天天进步201511 小时前
Python全栈项目--校园食堂点餐与推荐系统
开发语言·python