怎样把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)
相关推荐
qq_20690139几秒前
c++如何将浮点数按指定精度写入文本_setprecision用法【实战】
jvm·数据库·python
2401_865439633 分钟前
如何管理Oracle服务器的内核共享内存_shmmax与shmall计算
jvm·数据库·python
万粉变现经纪人8 分钟前
如何解决 pip install flash-attention 报错 需要 SM_80+(Ampere)架构 问题
python·架构·django·bug·virtualenv·pip·pygame
lulu121654407810 分钟前
Claude Code Routines功能深度解析:24小时云端自动化开发指南
java·人工智能·python·ai编程
2301_8148098613 分钟前
HTML函数能否用外接显卡坞提升性能_eGPU对HTML函数帮助【汇总】
jvm·数据库·python
DaqunChen13 分钟前
如何优化SQL注入检测性能_通过预编译缓存提升效率
jvm·数据库·python
坐吃山猪15 分钟前
Python20_MCP添加鉴权
开发语言·python
Greyson117 分钟前
如何通过Vagrant快速建库_自动化虚拟机Oracle部署方案
jvm·数据库·python
西西弗Sisyphus20 分钟前
Python 闭包实现的计数器,每调用一次就 +1,多个计数器之间互不干扰
python·闭包·closure
Wyz2012102422 分钟前
HTML函数运行时触控屏失灵是硬件故障吗_输入层兼容性测试【详解】
jvm·数据库·python