首页 存档 技术 查看内容

Python统计多个Powerpoint文件中幻灯片总数量

2018-3-30 13:00 |来自: 互联网 462 0

摘要: 晚上吃饭时突然想知道自己做了多少页《Python程序设计》系列教材的配套PPT,于是就有了下面的代码,这套PPT综合了《Python程序设计基础》(ISBN:9787302410584)、《Python程序设计(第2版)》(ISBN:978730243651 ...

晚上吃饭时突然想知道自己做了多少页《Python程序设计》系列教材的配套PPT,于是就有了下面的代码,这套PPT综合了《Python程序设计基础》(ISBN:9787302410584)、《Python程序设计(第2版)》(ISBN:9787302436515)和《Python可以这样学》(ISBN:9787302456469)以及将要出版的《Python程序设计开发宝典》4本书的内容,部分内容比书上详细,有的地方不如书上详细,主要是上课用,几本书重点介绍Python 3.4.x、3.5.x、3.6.x的语法和应用,全套课件均已免费分享。

import os
import os.path
import win32com
import win32com.client


total = 0


def pptCount(path):
global total
for subPath in os.listdir(path):
subPath = os.path.join(path, subPath)
if os.path.isdir(subPath):
pptCount(subPath)
elif subPath.endswith('.ppt'):
print(subPath)
powerpoint = win32com.client.Dispatch('PowerPoint.Application')
powerpoint.Visible = 1
ppt = powerpoint.Presentations.Open(subPath)
win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
total = ppt.Slides.Count
powerpoint.Quit()


pptCount('F:\\教学课件\\Python程序设计(第二版)')
print(total)


运行结果显示:

pptx肿么办?

首先:

pip install python-pptx

然后:

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部