怎样把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)
相关推荐
nbsaas-boot33 分钟前
Java 正则表达式白皮书:语法详解、工程实践与常用表达式库
开发语言·python·mysql
仗剑_走天涯35 分钟前
基于pytorch.nn模块实现线性模型
人工智能·pytorch·python·深度学习
chao_78937 分钟前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
chao_7895 小时前
二分查找篇——搜索旋转排序数组【LeetCode】一次二分查找
数据结构·python·算法·leetcode·二分查找
烛阴5 小时前
Python装饰器解除:如何让被装饰的函数重获自由?
前端·python
noravinsc6 小时前
django 一个表中包括id和parentid,如何通过parentid找到全部父爷id
python·django·sqlite
ajassi20006 小时前
开源 python 应用 开发(三)python语法介绍
linux·python·开源·自动化
沉默媛7 小时前
如何安装python以及jupyter notebook
开发语言·python·jupyter
Deng9452013148 小时前
基于Python的旅游数据可视化应用
python·numpy·pandas·旅游·数据可视化技术
2401_878624798 小时前
pytorch 自动微分
人工智能·pytorch·python·机器学习