用python将图片写入ppt_用python做ppt服务用于导入图片
項(xiàng)目需要做WINFORM程序與powerpoint交互,把winform生成的圖片自動(dòng)拷貝到ppt中。目前使用python做了一個(gè)簡(jiǎn)單的服務(wù)解決。由于要求是32位程序,所以下面全都是32位的版本。
第一步,安裝python2.7 32位。
第二部,安裝py2exe 32位。
第三步,安裝pywin32 32位。
第四步,用Eclipse(pydev插件)寫(xiě)代碼,見(jiàn)附件。主要內(nèi)容如下:
// wavy_ppt_service.pyimport?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()
就是用客戶端和服務(wù)端的方式做的一個(gè)服務(wù),服務(wù)端接收到數(shù)據(jù)后會(huì)將剪切板的圖片拷貝到ppt中。
打開(kāi)cmd,調(diào)用buildExe32.bat就可以生成dist目錄了,包含著exe 程序。
原文:http://2924037.blog.51cto.com/2914037/1692967
總結(jié)
以上是生活随笔為你收集整理的用python将图片写入ppt_用python做ppt服务用于导入图片的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python --- 使用conda配
- 下一篇: [python、flask] - POS