2015-03-08 36 views
6

我有一个数据提供者提供了一个DDE链接(我可以在Excel中使用)和一个在后台运行的exe文件作为数据管理器(不知道这是否就是所谓的DDE服务器)并且DDE链接连接到该exe文件。通过绕过Excel的Python Python中的DDE获取数据

我想绕过Excel并直接在Python中工作。我看到了有关DDE一些例子,但他们都在Python 2,我用Python 3

我看到这样做的净例子:

import win32ui 
import dde 
... 
... 
server = dde.CreateServer() 
server.Create("SomeName") 
... 

但这些例子说明如何创建DDE服务器。在我的情况下,有一个现有的EXE,它是数据管理器(DDE服务器可能?),并在Excel中有一个菜单,通过该我可以得到如

' = DataProviderFunc1(Param1, Param2)' 
' = DataProviderFunc2(Param1, Param2)' 

我想写的代码数据直接获取' = DataProviderFunc1(Param1, Param2)'等的输出的Python,而不是打开Excel工作表,然后让Python读取Excel工作表的输出。

这可能吗?

我正在使用Python 3.4。谢谢

在DDE模块上似乎只有很少的文档,例如, http://docs.activestate.com/activepython/2.4/pywin32/dde.html

+1

你有没有找到你的答案? – 2017-07-17 13:00:45

回答

0

最接近的事情文档我发现在这里: client exampleserver example

的例子,甚至没有注释,以便让我分享我想通了一个注释过的例子:

import win32ui 
import dde 

#apparently "servers" talk to "servers" 
server = dde.CreateServer() 
#servers get names but I'm not sure what use this name 
#has if you're acting like a client 
server.Create("TestClient") 
#use our server to start a conversation 
conversation = dde.CreateConversation(server) 

# RunAny is the server name, and RunAnyCommand is the topic 
conversation.ConnectTo("RunAny", "RunAnyCommand") 
# DoSomething is the command to execute 
conversation.Exec("DoSomething") 
# For my case I also needed the request function 
# request somedata and save the response in requested_data. 
requested_data = conversation.Request("somedata") 

主要功能似乎是执行和请求。两者都采取字符串,所以在你的特定情况下,你必须找出你的服务器需要什么。