怎样把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)
相关推荐
程序员:钧念5 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
数据与后端架构提升之路6 小时前
TeleTron 源码揭秘:如何用适配器模式“无缝魔改” Megatron-Core?
人工智能·python·适配器模式
hele_two7 小时前
快速幂算法
c++·python·算法
l1t7 小时前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独
Cemtery1169 小时前
Day26 常见的降维算法
人工智能·python·算法·机器学习
星空椰10 小时前
快速掌握FastAPI:高效构建Web API
python·fastapi
塔尖尖儿10 小时前
Python中range()到底是什么演示
python
Ethan-D11 小时前
#每日一题19 回溯 + 全排列思想
java·开发语言·python·算法·leetcode
weixin_4469340312 小时前
统计学中“in sample test”与“out of sample”有何区别?
人工智能·python·深度学习·机器学习·计算机视觉