怎样把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)
相关推荐
happylifetree39 分钟前
Python014-第二章13.数据容器-tuple案例
python
茉莉玫瑰花茶1 小时前
LangGraph 其他核心能力 [ 3 ]
python·ai
AI玫瑰助手1 小时前
Python函数:递归函数的定义与阶乘案例实现
开发语言·python·信息可视化
武子康1 小时前
调查研究-155 Open-LLM-VTuber 本地部署与互动实战指南
人工智能·python·深度学习·ai·数字人
北漂人Java1 小时前
Pycharm配置Miniconda教程
python·pycharm
CTA量化套保1 小时前
量化程序 while True 一直跑 CPU 很高:天勤降频与字段过滤
python·区块链
copyer_xyf2 小时前
Python 内存分析:从栈和堆理解对象引用
前端·后端·python
大蚂蚁2号2 小时前
深度剖析Python全局解释器锁(GIL):原理、瓶颈与终极破局方案
python
高洁012 小时前
打造行业知识图谱三步走
python·深度学习·数据挖掘·知识图谱
装不满的克莱因瓶2 小时前
使用 PyTorch Tensor 的相关数据处理
人工智能·pytorch·python·深度学习·机器学习·ai