Python输出PowerPoint(ppt)文件中全部文字信息的方法

yipeiwu_com7年前Python基础

本文实例讲述了Python输出PowerPoint(ppt)文件中全部文字信息的方法。分享给大家供大家参考。具体分析如下:

下面的代码依赖于windows com,所以必须在机器上安装PowerPoint才能用,可以将PPT文件中的所有纯文本信息进行输出到指定的文件,非常实用。

import win32com
from win32com.client import Dispatch, constants
ppt = win32com.client.Dispatch('PowerPoint.Application')
ppt.Visible = 1
pptSel = ppt.Presentations.Open("c:\\1.ppt")
win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
f = file("c:\\1.txt","w")
slide_count = pptSel.Slides.Count
for i in range(1,slide_count + 1):
  shape_count = pptSel.Slides(i).Shapes.Count
  print shape_count
  for j in range(1,shape_count + 1):
    if pptSel.Slides(i).Shapes(j).HasTextFrame:
      s = pptSel.Slides(i).Shapes(j).TextFrame.TextRange.Text
      f.write(s.encode('utf-8') + "\n")    
f.close()
ppt.Quit()

希望本文所述对大家的Python程序设计有所帮助。

相关文章

django-初始配置(纯手写)详解

我们通过django-admin startproject zhuyu命令创建好项目后,在pycharm中打开 我们需要在在该项目中,配置一些相关操作。 1、template(存放模板的...

python bluetooth蓝牙信息获取蓝牙设备类型的方法

python 获取蓝牙设备类型 扫描蓝牙设备获取到的信息中,无法判断扫描到的蓝牙设备属于什么类型的设备。 扫描蓝牙信息使用的是python 里面的bluetooth模块。 首先扫描出来的...

Python数据可视化库seaborn的使用总结

Python数据可视化库seaborn的使用总结

seaborn是python中的一个非常强大的数据可视化库,它集成了matplotlib,下图为seaborn的官网,如果遇到疑惑的地方可以到官网查看。http://seaborn.py...

对Pytorch中Tensor的各种池化操作解析

AdaptiveAvgPool1d(N) 对一个C*H*W的三维输入Tensor, 池化输出为C*H*N, 即按照H轴逐行对W轴平均池化 >>> a = torch...

python如何实现代码检查

前言 通常我们的python代码都是遵循PEP8的规范化格式,目的是为了保持代码的一致性、可读性。,这里给大家推荐几个常用的静态代码检查工具,大家可以酌情选择使用 1. pylint...