怎样把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_192779872 分钟前
如何用FastAPI构建高性能的现代API
jvm·数据库·python
癫狂的兔子3 分钟前
【bug】【Python】pandas中的DataFrame.to_excel()和ExcelWriter的区别
python·bug
生活很暖很治愈4 分钟前
Pytest-order插件
python·测试工具·测试用例·pytest
HeDongDong-4 分钟前
详解 Kotlin 的函数
开发语言·python·kotlin
啊阿狸不会拉杆5 分钟前
《数字信号处理》第5章-数字滤波器的基本结构
python·算法·机器学习·matlab·信号处理·数字信号处理·dsp
逄逄不是胖胖6 分钟前
《动手学深度学习》-56GRN实现
pytorch·python·深度学习
naruto_lnq8 分钟前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python
m0_5811241911 分钟前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
2401_8414956411 分钟前
【LeetCode刷题】二叉树的中序遍历
数据结构·python·算法·leetcode··递归·遍历
u01092727111 分钟前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python