怎样把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)
相关推荐
神奇元创7 小时前
商用级光路加速卡:大模型推理的极速落地方案
python·神经网络·fpga开发·dsp开发
运筹vivo@7 小时前
Python ContextVar 底层机制与内存模型拆解
前端·数据库·python
大白菜和MySQL7 小时前
java应用排查高线程
java·python
嵌入式协会20240727 小时前
(已解决)MinIO python 获取预签名出现forbidden、errornetwork等错误
java·开发语言·python
宸丶一7 小时前
Day 14:任务追踪 - 让 Agent 拥有项目管理能力
开发语言·python
skylar08 小时前
小白1分钟安装flash-attn
开发语言·python
JustNow_Man8 小时前
psmux快捷键
人工智能·python
默子昂8 小时前
ollama 自定义ui
开发语言·python·ui
abcy0712138 小时前
Python中使用FastAPI和HDFS进行异步文件上传
python·fastapi