安装环境(window下)
- 安装python
- 添加环境变量
右键我的电脑->属性->高级系统设置->系统变量->Path添加python的安装目录
- 升级pip,因为自带的pip是旧的
python -m pip install -U pip
- 添加环境变量
安装pywin32(其实是pypiwin32)
- pip install pypiwin32
安装OLE/COM(查看comAPI的文档)
- 下载安装,去这个地址,下载安装
- 进入安装目录
C:\Program Files (x86)\Resource Kit
,查看API
- 1 Type Libraries
- 2 Microsoft PowerPoint 14.0 Object Library(Ver 2.a)
代码
#!/usr/bin/env python2.7.14
# -*- coding: utf-8 -*-
# pip install pypiwin32
__author__ = 'ifeng'
import win32com
from win32com.client import Dispatch, constants
import sys
def obtainPPTNote(pptPath):
if pptPath.strip() == '':
print 'need a ppt \' path'
return
try:
listForNote = []
ppt = win32com.client.Dispatch('PowerPoint.Application')
ppt.Visible = 1
pptSel = ppt.Presentations.Open(pptPath) win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
slide_count = pptSel.Slides.Count
for i in range(1, slide_count + 1):
shape_count = pptSel.Slides(i).Shapes.Count
notePageRange = pptSel.Slides(i)
slideRange = notePageRange.NotesPage
noteShape = slideRange.Shapes.Placeholders(2)
notetxtFrame = noteShape.TextFrame
textrangestring = notetxtFrame.TextRange
text1 = textrangestring.Text
listForNote.append(text1.encode('utf-8'))
print text1
except:
print("opened is error for ppt")
finally:
ppt.Quit()
return listForNote
if __name__=='__main__':
obtainPPTNote("C:\\Users\\admin\\Desktop\\1.pptx")