怎样把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)
相关推荐
青 春 记 忆1 小时前
零基础入门python30:Flask个人账本从空目录运行与阶段验收
python·flask·后端开发
l1258651 小时前
# LangGraph Memory机制深度解析:短期记忆与长期记忆的工程实践
前端·人工智能·python·langchain·bootstrap
金銀銅鐵3 小时前
斐波那契数列的个位数出现的周期是多少?
python·数学
whcyhhh4 小时前
头歌实践教学平台:数据科学与大数据技术导论(十二)
大数据·开发语言·python·数据清洗
qq_316411034 小时前
专业的腹腔镜医疗器械物联网APP开发服务商
python
阿童木写作5 小时前
跨境电商翻译利器,批量图片视频翻译+智能抠图工具
python·音视频
绘梨衣5475 小时前
异步任务队列-学习2
爬虫·python·学习·任务队列
用户8356290780516 小时前
使用 Python 在 Excel 中插入 OLE 对象
后端·python
one3126 小时前
高精度MEMS电容式倾角传感器:原理、结构与Python三维可视化
开发语言·python
深蓝海拓7 小时前
基于QtPy (PySide6) 的PLC-HMI工程实战记录(七)创建适合HMI项目的数字输入/显示类部件
python