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中只有一种模块对象类型 ...
随机推荐
- tcl之变量-简单变量
- 使用cxf 发布 jax-rs 风格webservice 。并客户端测试。
详细介绍:http://www.ibm.com/developerworks/cn/java/j-lo-jaxrs/ 1.定义一个User对象 package com.zf.test; import ...
- 739. Daily Temperatures
https://leetcode.com/problems/daily-temperatures/description/ class Solution { public: vector<int ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- 栈经典列题:Rails
解题心得: 1.这题是先进后出的顺序,所以使用栈(先进后出表). 2.搞清楚题意,需要达成的序列和进入的序.不要弄混了. 3.思维混乱的时候要冷静,冷静,冷静~~~~! 题目: Description ...
- 洛谷 P2205 [USACO13JAN]画栅栏
这题其实没什么,但用到的算法都十分有用.做一个不恰当的比喻,这是一只必须用牛刀杀的鸡,但因为我这个蒟蒻杀不死牛,所以只能找只鸡来练练手. 题目描述 Farmer John 想出了一个给牛棚旁的长围墙涂 ...
- collections模块简介
collections模块简介 除python提供的内置数据类型(int.float.str.list.tuple.dict)外,collections模块还提供了其他数据类型,使用如下功能需先导入c ...
- (ADO.NET)SqlCommand参数化查询
string strcon = "Persist Security Info=False;User id=sa;pwd=lovemary;database=student;server=(l ...
- asp.net中使用ffmpeg
protected void Button1_Click(object sender, EventArgs e) { string FFmpegArguments = @" -i D:\离歌 ...
- MongoDB快速入门学习笔记2 MongoDB的概念及简单操作
1.以下列举普通的关系型数据库和MongoDB数据库简单概念上的区别: 关系型数据库 MongoDB数据库 说明 database database 数据库 table collection 数据库表 ...