Integrate a GUI in a excel sheed

Brian Kelley bkelley at wi.mit.edu
Tue Feb 18 17:43:25 CET 2003


I have actually done this and it wasn't very easy.  The basic steps that 
  I took were as follows.

Excel -->  Visual Basic Wrapper --> Python COM Server --> os.spawn 
Remote wxPython GUI application

Spawning the GUI doesn't block the COM server which is essential. 
Otherwise EXCEL hangs very hard.

So getting the data into the remote GUI was fairly easy.  The hard part 
was letting the COM server "know" where the GUI app was located so it 
could be launched from a system call.  I used the windows registry for 
this purpose and my had installer write the location of the gui app.

Now the hard part, what about getting data *back* into excel?

When the GUI is called it is sent the Active workbook and worksheet 
numbers along with any relavant cell information and data.  If the 
remote GUI has the workbook and worksheet it can write any desired 
information back to excel.

 >>> ms = client.Dispatch("Excel.Application")
 >>> book = ms.Workbooks(1) # appropriate workbook #
 >>> book.Worksheets(1)     # appropriate sheet #
 >>> sheet = book.Worksheets(1)
 >>> sheet.Cells(1,1).Value = "foo"

What are the problems with this approach?  wxPython startup times are 
abyssmal and the overhead is huge about 10MB.  The COM server doesn't 
talk to the GUI so EXCEL really can't inspect any GUI states.  You could 
fix this by letting the COM Object query the GUI through a socket or 
file based interface.

I think that this approach would be pretty good for your application. 
You aren't really "embedding" wxPython into excel, merely launching it 
with a mechanism for excel automation.

I actually just submitted a proposal for a Python tutorial for this at 
PyCON so I'm delighted to see that someone may actually use it :)  Even 
if I don't do the tutorial I will be writing up the whole processes. 
Feel free to ask any more questions if you are interested.  I am 
actually using this approach in a commercial product (which means that I 
feel relatively confident that it is stable)

Brian





More information about the Python-list mailing list