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

WBOY
Release: 2016-06-10 15:13:59
Original
1743 people have browsed it

本文实例讲述了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()
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template