iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >用python做ppt服务用于导入图片
  • 197
分享到

用python做ppt服务用于导入图片

图片pythonppt 2023-01-31 02:01:11 197人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

项目需要做winform程序与powerpoint交互,把winfORM生成的图片自动拷贝到ppt中。目前使用python做了一个简单的服务解决。由于要求是32位程序,所以下面全都是32位的版本。第一步,安装Python2.7 32位。第二

项目需要做winform程序与powerpoint交互,把winfORM生成的图片自动拷贝到ppt中。目前使用python做了一个简单的服务解决。由于要求是32位程序,所以下面全都是32位的版本。

第一步,安装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 程序。

--结束END--

本文标题: 用python做ppt服务用于导入图片

本文链接: https://www.lsjlt.com/news/186674.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作