首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python读取ppt文本内容

python读取ppt文本内容

作者头像
py3study
发布2020-01-10 16:54:44
发布2020-01-10 16:54:44
4.1K0
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
import win32com
from win32com.client import Dispatch, constants
ppt = win32com.client.Dispatch('PowerPoint.Application')
ppt.Visible = 1
pptSel = ppt.Presentations.Open("C:\\web\\phpStudy\\WWW\\ppt\\Russia\\1.pptx")
# win32com.client.gencache.EnsureDispatch('PowerPoint.Application')

#get the ppt's pages
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
      print (s.encode('utf-8')+ "\n")

ppt.Quit()

使用前需要配置win32库 安装非常简单

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档