Calling Python Script from MS Excel?

K

Kevin T. Ryan

Hi Group -

I have written a "semi-program" in MS Excel related to running a football
pool. I've updated it over the past two years or so, to the point where it
is getting pretty advanced. Only, there are a few tricks that I want to
add that I could not do in Excel - so I did them in Python :) Except as it
stands, the current python scripts have to be run via the command line.
Does anyone know how to allow interaction between Excel and Python via
EXCEL?

I've looked on Mark Hammond's page, and I've figured out how to interact
with Python and Excel from PYTHON, but I can't seem to find the right info
for making the calls from the other end (i.e. from Excel). Any advice
would be GREATLY appreciated!

PS - If anyone has any interest in this type of program, please let me know
- I'd be more than willing to release via the GPL or something to that
effect. Thanks Again...
 
F

fishboy

Hi Group -

I have written a "semi-program" in MS Excel related to running a football
pool. I've updated it over the past two years or so, to the point where it
is getting pretty advanced. Only, there are a few tricks that I want to
add that I could not do in Excel - so I did them in Python :) Except as it
stands, the current python scripts have to be run via the command line.
Does anyone know how to allow interaction between Excel and Python via
EXCEL?

I've looked on Mark Hammond's page, and I've figured out how to interact
with Python and Excel from PYTHON, but I can't seem to find the right info
for making the calls from the other end (i.e. from Excel). Any advice
would be GREATLY appreciated!

PS - If anyone has any interest in this type of program, please let me know
- I'd be more than willing to release via the GPL or something to that
effect. Thanks Again...

You can use COM to go both ways. Just create a COM server in Python
and register it so that Excel can find it.

Check out "Quick Start to Server side COM and Python" in the win32
documents.

You will have to write a little VBScript on the excel side to
interface, I think.
 
G

Giles Brown

Kevin T. Ryan said:
Hi Group -

I have written a "semi-program" in MS Excel related to running a football
pool. I've updated it over the past two years or so, to the point where it
is getting pretty advanced. Only, there are a few tricks that I want to
add that I could not do in Excel - so I did them in Python :) Except as it
stands, the current python scripts have to be run via the command line.
Does anyone know how to allow interaction between Excel and Python via
EXCEL?

I've looked on Mark Hammond's page, and I've figured out how to interact
with Python and Excel from PYTHON, but I can't seem to find the right info
for making the calls from the other end (i.e. from Excel). Any advice
would be GREATLY appreciated!

One way of approaching this would be to package your Python code
as a COM server. This is actually much easier than you might think
(this reference is quite old but is still relevant):

http://www.python.org/windows/win32com/QuickStartServerCom.html

You can make calls on your object from Excel VBA. For example you
could call on the object in the reference above as:

Dim HelloWorld As Object

Set HelloWorld = CreateObject("testcomserver.HelloWorld")
MsgBox HelloWorld.Hello("Kevin")

Hth,
Giles
 
Joined
Jun 10, 2008
Messages
1
Reaction score
0
You might want to take a look at Resolver One - it's a program that allows you to integrate Python code into your spreadsheets. Alternatively, I think you can do some level of Python scripting in OpenOffice Calc - I haven't tried that myself, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top