怎样把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)
相关推荐
青 春 记 忆2 小时前
Dify Docker Compose 通用无损升级指南:从备份、双版本预演到切换与回滚
运维·人工智能·python·docker·容器
GlueNa2SiO32 小时前
03-Flask模板引擎Jinja2详解
笔记·python·flask
临沂GEO4 小时前
GEO搜索优化科普|正规地理位置流量运营入门指南
大数据·人工智能·python·流量运营
大模型码小白4 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring
荷蒲6 小时前
【小白量化Qbuddy】利用AI学习中文Python
人工智能·python·学习
数据狐(Datafox)7 小时前
京东商品列表API技术解析与落地应用(含标准 JSON 示例)
java·大数据·前端·人工智能·python·数据分析·json
量化吞吐机7 小时前
2026年下半年手工交易规则走向量化表达,产品该先接住哪一步
人工智能·python
Metaphor6928 小时前
使用 Python 读取和删除 Excel 文件属性
python·excel
迷迭香yy9 小时前
Python构建转融券多空识别系统从接口到因子的全流程 IG50免费开源股票数据API接口
开发语言·python·开源
月光船幽幽9 小时前
真实即粗糙,光滑是伪造
人工智能·python