怎样把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)
相关推荐
langzaibeijing4 分钟前
性价比高的AI应用厂家
大数据·人工智能·python
Gerardisite6 分钟前
企业微信 API 能做什么?
人工智能·python·自动化·企业微信
测试员周周12 分钟前
【Appium 系列】第09节-数据驱动测试 — YAML 数据 + parametrize
服务器·数据库·人工智能·python·测试工具·语言模型·appium
不能隔夜的咖喱13 分钟前
黑马ai大模型笔记(自用,比较粗糙)
linux·windows·python
周公14 分钟前
记一次在双 RTX 3090 工作站上部署 vLLM 与 Qwen3.6-35B-AWQ 的实战记录
python·ai·llama·vllm·ollama
yexuhgu25 分钟前
html如何修改备注
jvm·数据库·python
AI技术控26 分钟前
Prompt Engineering 在企业大模型应用中的实践:从提示词模板到可控输出
人工智能·python·深度学习·语言模型·自然语言处理·prompt
Marry Andy28 分钟前
langgenius/dify-sandbox:0.2.12启动崩溃
人工智能·经验分享·python
被AI抢饭碗的人32 分钟前
C++过渡Python
开发语言·python
m0_7335654640 分钟前
golang如何使用Wails开发桌面应用_golang Wails桌面应用开发步骤
jvm·数据库·python