python操作word、ppt的详解
python使用win32com的心得
主要是有个项目可能要用到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.
我就是安装的时候点的太快,结果忘记了路径,重新点击安装,记下了路径。
软件的界面样子大概是:
记得要在右侧的
现在操作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操作word、ppt的详解的更多相关文章
- Python操作redis字符串(String)详解 (三)
# -*- coding: utf-8 -*- import redis #这个redis不能用,请根据自己的需要修改 r =redis.Redis(host=") 1.SET 命令用于设置 ...
- python接口自动化(三十八)-python操作mysql数据库(详解)
简介 现在的招聘要求对QA人员的要求越来越高,测试的一些基础知识就不必说了,来说测试知识以外的,会不会一门或者多门开发与语言,能不能读懂代码,会不会Linux,会不会搭建测试系统,会不会常用的数据库, ...
- Python中的高级数据结构详解
这篇文章主要介绍了Python中的高级数据结构详解,本文讲解了Collection.Array.Heapq.Bisect.Weakref.Copy以及Pprint这些数据结构的用法,需要的朋友可以参考 ...
- Python调用windows下DLL详解
Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...
- Python安装、配置图文详解(转载)
Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境(I ...
- 【和我一起学python吧】Python安装、配置图文详解
Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境( ...
- Python中格式化format()方法详解
Python中格式化format()方法详解 Python中格式化输出字符串使用format()函数, 字符串即类, 可以使用方法; Python是完全面向对象的语言, 任何东西都是对象; 字符串的参 ...
- python操作word
python教程(百度经验) Python 操作Word(Excel.PPT等通用) import win32comfrom win32com.client import Dispatch, co ...
- Python 单向队列Queue模块详解
Python 单向队列Queue模块详解 单向队列Queue,先进先出 '''A multi-producer, multi-consumer queue.''' try: import thread ...
- Python包模块化调用方式详解
Python包模块化调用方式详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一般来说,编程语言中,库.包.模块是同一种概念,是代码组织方式. Python中只有一种模块对象类型 ...
随机推荐
- web端图片文件直传
采用JS客户端直接签名有一个很严重的安全隐患.就是OSS AccessId/AccessKey暴露在前端页面.可以随意拿到AccessId/AccessKey,这是非常不安全的做法. 本文将此例子进化 ...
- 使用cxf 发布 jax-rs 风格webservice 。并客户端测试。
详细介绍:http://www.ibm.com/developerworks/cn/java/j-lo-jaxrs/ 1.定义一个User对象 package com.zf.test; import ...
- git 远程仓库 与本地项目 挂钩 全过程
摘要:学了Android 快三个月了,依旧不会git,真的有些丢人.git是一个非常棒的团队协作的工具.其实也是分分钟的事情.Follow Me! Step 1 在码云上新建一个项目,作为远程仓库.里 ...
- mysql练习题练习
1.数据库是按照原文制作的,表格结构一样具体存储的数据有些差异 原文地址:MySQL练习题 原答案地址:MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: selec ...
- ffmpeg转换参数和对几种视频格式的转换分析
我们在将多种格式的视频转换成flv格式的时候,我们关注的就是转换后的flv视频的品质和大小.下面就自己的实践所得来和大家分享一下,主要针对avi.3gp.mp4和wmv四种格式来进行分析.通常在使用f ...
- 纯js国际化(i18n)
i18n,是internationalization单词的简写,中间18个字符略去,简称i18n,意图就是实现国际化,方便产品在不同的场景下使用 目标:可以点击切换语言或者ChangeLanguage ...
- leetcode 【 Unique Paths 】python 实现
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- IIS6.0,Apache低版本,PHP CGI 解析漏洞
IIS6.0解析漏洞 在IIS6.0下存在这样的文件"名字.asp;名字.jpg" 代表了jpg文件可以以asp脚本类型的文件执行. 根据这个解析漏洞我们可以上传这种名字类型的图片 ...
- Java开发微信公众号(四)---微信服务器post消息体的接收及消息的处理
在前几节文章中我们讲述了微信公众号环境的搭建.如何接入微信公众平台.以及微信服务器请求消息,响应消息,事件消息以及工具处理类的封装:接下来我们重点说一下-微信服务器post消息体的接收及消息的处理,这 ...
- 【bzoj1146】[CTSC2008]网络管理Network 倍增LCA+dfs序+树状数组+主席树
题目描述 M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个部门之间协同工作,公司搭建了一个连接整个公司的通信网络.该网络的结构由N个路由器和N-1条高 ...