怎样把pptx课件转换成word文档

如果你还没有安装python-pptxpython-docx,请先运行以下命令:

pip install python-pptx python-docx
 

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)

相关推荐

  1. 怎样pptx转换word文档

    2024-07-14 04:56:03       28 阅读
  2. 怎么数据转换百度k线图

    2024-07-14 04:56:03       27 阅读
  3. json文件转换excel格式文件

    2024-07-14 04:56:03       37 阅读
  4. python将word文件转换pdf文件

    2024-07-14 04:56:03       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 04:56:03       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 04:56:03       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 04:56:03       62 阅读
  4. Python语言-面向对象

    2024-07-14 04:56:03       72 阅读

热门阅读

  1. Github 2024-07-13 Rust开源项目日报 Top10

    2024-07-14 04:56:03       26 阅读
  2. 设计模式详解(十八)——责任链模式

    2024-07-14 04:56:03       21 阅读
  3. Vue3 关于scss预编译中:deep 其中的deep如何理解

    2024-07-14 04:56:03       23 阅读
  4. stm32使用通用定时器生成pwm

    2024-07-14 04:56:03       26 阅读
  5. 如何实现一个分布式锁

    2024-07-14 04:56:03       19 阅读
  6. BGP笔记的基本概要

    2024-07-14 04:56:03       24 阅读
  7. 在RHEL9.4上安装Python3.11环境

    2024-07-14 04:56:03       21 阅读
  8. Hypertable install of rhel6.0

    2024-07-14 04:56:03       24 阅读
  9. 60、基于浅层神经网络的数据拟合(matlab)

    2024-07-14 04:56:03       27 阅读
  10. conda激活的虚拟环境的python版本不对应

    2024-07-14 04:56:03       23 阅读
  11. 实变函数精解【4】

    2024-07-14 04:56:03       22 阅读