Retrieve data via DDE in Python by crawling Excel

I have a data provider that provides a DDE link (which I can use in Excel) and an exe file that runs in the background that serves as a data manager (not sure if this is what is called a DDE server) and the DDE link is connected to this exe file.

I want to get around Excel and work directly in Python. I saw several DDE examples, but they were all in Python 2, and I use Python 3.

I saw examples on the net that do something like:

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

But these examples show how to create a DDE server. In my case, there is an existing exe that is a data manager (maybe a DDE server?), And in Excel there is a menu through which I can get data, such as

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

I want to write code in Python that directly receives the output of ' = DataProviderFunc1(Param1, Param2)' , etc., instead of opening an Excel worksheet, and then letting Python read the output from the Excel worksheet.

Is it possible?

I am using Python 3.4. Thanks

The DDE module seems to have very few documents, for example. http://docs.activestate.com/activepython/2.4/pywin32/dde.html

+6
source share
1 answer

The closest to the documentation I found are given here: client example, server example

The examples are not even commented on, so let me share what I found out with a comment:

 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") 

Key functions look like Exec and Request. Both take strings, so in your particular case you will need to find out what your server wants.

0
source

Source: https://habr.com/ru/post/983512/


All Articles