python可以使用一个第三方库叫做win32com达到操作com的目的, 我是安装了ActivePython的第三方库,从官网下载了安装包,该第三方库几乎封装了所有python下面的win32相关的操作,例如win32api,win32gui等等,可以说是比较齐全的了,下载地址可以自行百度获取。

主要是有个项目可能要用到ppt转换成视频的功能。 之后在想使用com操作excel还有word,ppt的时候,相信大部分人跟我一样,都是搜索python如何操作ppt,或者win32com操作office之类的搜索语句, 搜索完毕之后,点进去之 后,几乎都直接是代码了,我觉得这样看得我云里雾里的,如果想做些其它操作都做不到,我当时的想法是想知道这些com的操作,究竟在哪里可以查找的到,因 为网上只是有限的几个操作,注入往ppt添加图片,或者doc转成pdf之类的,而实际上的office的com操作时不止这些函数的,那么我们怎么知道 其它的api呢?这样子我们就可以脱离网上的代码,自己编写com代码了。

一番查找,谷歌之后,在一个网页上终于找到了答案:

Querying Interfaces

Now, how does one investigate the detail of each object? For example, how does one access the name of a folder? Firstly, it helps to know the interface that the object exposes, and this information can be found in several places:

The Microsoft API documentation.

Other useful sources, such as the "Outlook Exchange" documentation.

The interface file generated by the "COM Makepy utility". To know which file is relevant to the interface in question, either perform a "grep" search for the name of the interface on the win32com/gen_py directory within your Python distribution, or invoke an erroneous method or access a non-existent attribute on an object with that interface in order to see what the name of the interface file is.

The "OLE/COM Object Viewer" in the "Tools" menu in Microsoft Visual C++ (at least in Visual Studio 6.0).

Once opened, the "Interfaces" section of the information hierarchy can be explored to reveal some "_Application" entries. For one of these, the information pane will mention "Microsoft Outlook 9.0 Object Library" under "TypeLib", for example.

Double-clicking on an "_Application" entry will provide an "ITypeInfo Viewer" which contains a "_Methods" section describing the available methods on the application's automation object.

The "Type Libraries" section of the information hierarchy will list, for example, "Microsoft Outlook 9.0 Object Library", and this can be investigated by double-clicking on that entry.

Hopefully, however, the object that you are accessing is known well enough by PythonWin to permit some kind of attribute or method completion on it. You should only need to resort to the above when more detailed knowledge about a method or attribute is required. You can also try something like this:

dir(object.__class__)

The name of a folder can be accessed as follows:

object.Name # Where object refers to a folder.

这里的第四个方法就是我找到的确认有效的,其它三个如果有兴趣的可以试试,第四个方法那就是ole/com object viewer工具,百度之下,下载了一个这样的工具,据说安装了vs之后是有的,

不过由于我不知道可执行程序的名字,也无从找起,于是重新下载了一个完整的工具,安装之后

默认安装路径是:C:\Program Files (x86)\Resource Kit

我就是安装的时候点的太快,结果忘记了路径,重新点击安装,记下了路径。

这个工具名字叫做oleview.exe,打开的时候,提示缺少了什么dll,没关系。

因为我现在知道名字了,然后使用everything搜索了工具,在我的visual studio里面同样找到了该工具,这下子可以完美打开了。

软件的界面样子大概是:

记得要在右侧的

Type Libraries里面找到相关的library,这里我需要操作的是powerpoint,也就是ppt

找到之后,双击打开它。

在右侧的就是一个列表,左侧的就是对于的内容,刚刚打开的时候,左侧显示的是完整的PowerPoint的api。

由于这个工具,不能够ctrl+f查找,我们可以ctrl+a,复制左侧的内容到文本中,使用其他诸如sublime文本编辑器执行查找功能。

下面搜索一下:saveAs(大概就是这个意思,我想找一个api可以另存为ppt为视频的操作)

我们找到了这个函数,同时结合网上的例子,我们就知道怎么使用了,传入的第一个参数是FileName,顾名思义就是文件名,第二个是int类型的fileFormat,如果是网上的例子的话,多半只会告诉你一个转换成pdf的代码,但是现在我要的是转成视频。

我们回到ole viewer,看看有没有fileformat的信息。 果不其然,发现了这样的代码:

PpSaveAsFileType

双击它

在最后,我找到了ppSaveAsWMV,很好,这样子我们就可以结合网上的例子,修改了。

现在操作ppt的方法我们弄明白了,那么操作word,excel也是一样的道理。 顺便封装了一个comppt.py的操作,由于刚写python,代码不是很溜:

__author__ = 'zxc'

import win32com.client

import time

import os

ppSaveAsWMV = 37

# only for windows platform and with the microsoft office 2010 or above,it needs the library win32com

def cover_ppt_to_wmv(ppt_src,wmv_target):

ppt = win32com.client.Dispatch('PowerPoint.Application')

presentation = ppt.Presentations.Open(ppt_src,WithWindow=False)

presentation.CreateVideo(wmv_target,-1,4,720,24,60)

start_time_stamp = time.time()

while True:

time.sleep(4)

try:

os.rename(wmv_target,wmv_target)

print 'success'

break

except Exception, e:

pass

end_time_stamp=time.time()

print end_time_stamp-start_time_stamp

ppt.Quit()

pass

if __name__ == '__main__':

cover_ppt_to_wmv('d:\\python\\demo.ppt','d:\\python\\demo.wmv')

python 经典ppt_python操作word、ppt的详解相关推荐

  1. python集合的操作_Python集合操作方法详解

    集合是无序的,天生不重复的数据组合,它的作用如下: 去重,即:把一个列表变成集合,就去重了 关系测试,即:测试两组集合的交集.并集和差集等 一.集合常用方法总结 二.定义 1.语法 >>& ...

  2. python 经典ppt_python入门分享.ppt

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbspPython python入门分享.ppt24页 本文档一共被下 ...

  3. python爬虫selenium操作下拉框详解

    使用python爬虫的selenium操作网页的下拉框. 以该网站为例:https://www.17sucai.com/pins/demo-show?id=5926 该网页下存在多个可供测试的下拉框. ...

  4. python中unicode编码表_Python中的字符串操作和编码Unicode详解

    本文主要给大家介绍了关于 Python中的字符串操作和编码Unicode的一些知识,下面话不多说,需要的朋友们下面来一起学习吧. 字符串类型 str:Unicode字符串.采用''或者r''构造的字符 ...

  5. python 文字语音朗读-python 利用pyttsx3文字转语音过程详解

    这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # -*- coding: ut ...

  6. python发音语言-python 利用pyttsx3文字转语音过程详解

    这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下# -*- coding: utf ...

  7. python发音模块-python 利用pyttsx3文字转语音过程详解

    这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # -*- coding: ut ...

  8. python装饰器详解-Python装饰器基础概念与用法详解

    本文实例讲述了Python装饰器基础概念与用法.分享给大家供大家参考,具体如下: 装饰器基础 前面快速介绍了装饰器的语法,在这里,我们将深入装饰器内部工作机制,更详细更系统地介绍装饰器的内容,并学习自 ...

  9. php操作ElasticSearch搜索引擎流程详解

    更多python.php教程请到友情连接: 菜鸟教程https://www.piaodoo.com 茂名一技http://www.enechn.com ppt制作教程步骤 http://www.tpy ...

最新文章

  1. python 第一行非零_python – 沿着已排序的二维numpy数组的轴查找第一个非零值
  2. bzoj4592[SHOI2015]脑洞治疗仪
  3. 【图文解释】快速排序算法
  4. 《网络安全原理与实践》一2.1 安全区介绍
  5. 7-93 矩阵A乘以B (15 分)
  6. 在R中创建晶须和盒图
  7. Atitit.可视化编程jbpm6 的环境and 使用总结...
  8. oracle shared_pool_size 0,Oracle 参数shared_pool_size
  9. rbf神经网络和bp神经网络,rbf神经网络百度百科
  10. 计算机主机的光驱怎么打开,笔记本电脑光驱,教您笔记本光驱怎么打开
  11. 自学前端第十八天:CSS精准定位position
  12. Eclipse中怎样设置字体大小和修改注释字体的颜色
  13. 世道变了 – 你愿意成为微软认证Linux工程师吗?
  14. css 遥控器界面,智能电视用户体验设计之遥控器篇
  15. SpringBoot集成MinIo实现资源库功能
  16. 软件项目管理:项目调研
  17. C++ 编写模板程序
  18. 教你在windows系统 VMware 软件中安装Ubuntu(附图文教程)超详细
  19. 高德地图开发自定义地图样式
  20. 英语演讲中式建筑PPT模板

热门文章

  1. [游戏开发]手机发热问题总结
  2. 解决nw.js中无法播放mp3音频问题
  3. B站-王卓-数据结构课程-学习笔记
  4. Linux网络编程(六)-高并发服务器03-I/O多路复用03:epoll【红黑树;根节点为监听节点】【无宏FD_SETSIZE限制;不需每次都将要监听的文件描述符从应用层拷贝到内核;不需遍历树】
  5. 国产家用投影仪十大排名品牌,最新排名整理分享给大家选前要看哦
  6. Web Services 接口大全
  7. 想在抖音挣钱,带你了解抖音自媒体的流量获取攻略
  8. 哈希算法、HD5、SHA-1
  9. 卸载python教程
  10. day7CSS3新特性