用python做ppt服务用于导入图片
2015-09-09 08:24
651 查看
项目需要做WINFORM程序与powerpoint交互,把winform生成的图片自动拷贝到ppt中。目前使用python做了一个简单的服务解决。由于要求是32位程序,所以下面全都是32位的版本。
第一步,安装python2.7 32位。
第二部,安装py2exe 32位。
第三步,安装pywin32 32位。
第四步,用Eclipse(pydev插件)写代码,见附件。主要内容如下:
// wavy_ppt_service.py
打开cmd,调用buildExe32.bat就可以生成dist目录了,包含着exe 程序。
附件:http://down.51cto.com/data/2366113
第一步,安装python2.7 32位。
第二部,安装py2exe 32位。
第三步,安装pywin32 32位。
第四步,用Eclipse(pydev插件)写代码,见附件。主要内容如下:
// wavy_ppt_service.py
import SocketServer import win32com.client import sys class MyTCPHandler(SocketServer.BaseRequestHandler): """ The RequestHandler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() # print "{} wrote:".format(self.client_address[0]) # print self.data # just send back the same data, but upper-cased # self.request.sendall(self.data.upper()) Application = win32com.client.Dispatch("PowerPoint.Application") currentSlide = Application.ActiveWindow.View.Slide currentSlide.Shapes.Paste() HOST, PORT = "localhost", int(sys.argv[1]) #HOST, PORT = "localhost", 9999 # Create the server, binding to localhost on port 9999 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) # Activate the server; this will keep running until you # interrupt the program with Ctrl-C server.serve_forever()就是用客户端和服务端的方式做的一个服务,服务端接收到数据后会将剪切板的图片拷贝到ppt中。
打开cmd,调用buildExe32.bat就可以生成dist目录了,包含着exe 程序。
附件:http://down.51cto.com/data/2366113
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法