怎样把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实现打包贪吃蛇游戏
开发语言·python·游戏
0思必得09 小时前
[Web自动化] Selenium处理动态网页
前端·爬虫·python·selenium·自动化
韩立学长9 小时前
【开题答辩实录分享】以《基于Python的大学超市仓储信息管理系统的设计与实现》为例进行选题答辩实录分享
开发语言·python
qq_192779879 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
u01092727110 小时前
使用Plotly创建交互式图表
jvm·数据库·python
爱学习的阿磊10 小时前
Python GUI开发:Tkinter入门教程
jvm·数据库·python
Imm77710 小时前
中国知名的车膜品牌推荐几家
人工智能·python
tudficdew10 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python
sjjhd65211 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
2301_8213696111 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python