Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Calling Python functions from Excel

Reply
Thread Tools

Calling Python functions from Excel

 
 
Cannonbiker
Guest
Posts: n/a
 
      11-15-2009
Hi,
unfortunately is my question about server COM (win32com)
http://groups.google.com/group/comp....04cec7f58c6a7#
without answer.

Please I need Calling Python functions from Excel and receive result
back in Excel. Can me somebody advise simplest solution please? I am
more VBA programmer than Python.

Thanks
 
Reply With Quote
 
 
 
 
Carsten Haese
Guest
Posts: n/a
 
      11-15-2009
Cannonbiker wrote:
> Please I need Calling Python functions from Excel and receive result
> back in Excel. Can me somebody advise simplest solution please? I am
> more VBA programmer than Python.


Maybe this will help:
http://oreilly.com/catalog/pythonwin...pter/ch12.html (Scroll down to
"Implementing a COM Server.")

--
Carsten Haese
http://informixdb.sourceforge.net

 
Reply With Quote
 
 
 
 
Darcy Mason
Guest
Posts: n/a
 
      11-16-2009
On Nov 15, 2:20*am, Cannonbiker <(E-Mail Removed)> wrote:

> Please I need Calling Python functions from Excel and receive result
> back in Excel. Can me somebody advise simplest solution please? I am
> more VBA programmer than Python.


A couple of years ago I used MSScriptControl for this. Couldn't find a
great reference just now, but here is a discussion which should give
enough information:
http://www.velocityreviews.com/forum...-in-excel.html

Check from around message 3 on.
 
Reply With Quote
 
Chris Withers
Guest
Posts: n/a
 
      11-17-2009
Cannonbiker wrote:
> Hi,
> unfortunately is my question about server COM (win32com)
> http://groups.google.com/group/comp....04cec7f58c6a7#
> without answer.
>
> Please I need Calling Python functions from Excel and receive result
> back in Excel. Can me somebody advise simplest solution please? I am
> more VBA programmer than Python.


Try http://code.google.com/p/pyinex/

cheers,

Chris

 
Reply With Quote
 
Mark Tolonen
Guest
Posts: n/a
 
      11-17-2009

"Chris Withers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Cannonbiker wrote:
>> Hi,
>> unfortunately is my question about server COM (win32com)
>> http://groups.google.com/group/comp....04cec7f58c6a7#
>> without answer.
>>
>> Please I need Calling Python functions from Excel and receive result
>> back in Excel. Can me somebody advise simplest solution please? I am
>> more VBA programmer than Python.

>
> Try http://code.google.com/p/pyinex/


The book Python: Programming on Win32 has a whole chapter on COM, and a
section on COM servers.

-Mark


 
Reply With Quote
 
Chris Withers
Guest
Posts: n/a
 
      11-17-2009
Mark Tolonen wrote:
>
>>> Please I need Calling Python functions from Excel and receive result
>>> back in Excel. Can me somebody advise simplest solution please? I am
>>> more VBA programmer than Python.

>>
>> Try http://code.google.com/p/pyinex/

>
> The book Python: Programming on Win32 has a whole chapter on COM, and a
> section on COM servers.


....and it's generally accepted that COM sucks rocks through straws, so
explore alternatives when they're available

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
 
Reply With Quote
 
Mark Tolonen
Guest
Posts: n/a
 
      11-18-2009

"Chris Withers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mark Tolonen wrote:
>>
>>>> Please I need Calling Python functions from Excel and receive result
>>>> back in Excel. Can me somebody advise simplest solution please? I am
>>>> more VBA programmer than Python.
>>>
>>> Try http://code.google.com/p/pyinex/

>>
>> The book Python: Programming on Win32 has a whole chapter on COM, and a
>> section on COM servers.

>
> ...and it's generally accepted that COM sucks rocks through straws, so
> explore alternatives when they're available
>
> Chris


True, but as usual Python makes it pretty darn easy (requires PyWin32):

------------- ex.py -------------------------------
class Example(object):
_public_methods_ = ['Add','Mul']
_reg_progid_ = 'MyPython.Example'
_reg_clsid_ = '{insert_GUID_here}'

def Add(self,a,b):
return a+b

def Mul(self,a,b):
return a*b

if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(Example)
---------------------------------------------------------

-------------- Excel Macro ----------------------
Sub Testit()
Set ex = CreateObject("MyPython.Example")
Range("A1") = ex.Add(1, 2)
Range("A2") = ex.Mul(3, 4)
End Sub
--------------------------------------------------------

Just run the script to register the server. "ex.py --unregister" will
remove it.

-Mark


 
Reply With Quote
 
Ethan Furman
Guest
Posts: n/a
 
      11-18-2009
Chris Withers wrote:
> Mark Tolonen wrote:
>> The book Python: Programming on Win32 has a whole chapter on COM, and
>> a section on COM servers.

>
> ...and it's generally accepted that COM sucks rocks through straws, so
> explore alternatives when they're available


+1 QOTW
 
Reply With Quote
 
Cannonbiker
Guest
Posts: n/a
 
      11-18-2009
On 18 lis, 03:09, "Mark Tolonen" <(E-Mail Removed)> wrote:
> "Chris Withers" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > Mark Tolonen wrote:

>
> >>>> Please I need Calling Python functions from Excel and receive result
> >>>> back in Excel. Can me somebody advise simplest solution please? I am
> >>>> more VBA programmer than Python.

>
> >>> Tryhttp://code.google.com/p/pyinex/

>
> >> The book Python: Programming on Win32 has a whole chapter on COM, and a
> >> section on COM servers.

>
> > ...and it's generally accepted that COM sucks rocks through straws, so
> > explore alternatives when they're available

>
> > Chris

>
> True, but as usual Python makes it pretty darn easy (requires PyWin32):
>
> ------------- ex.py -------------------------------
> class Example(object):
> * * _public_methods_ = ['Add','Mul']
> * * _reg_progid_ = 'MyPython.Example'
> * * _reg_clsid_ = '{insert_GUID_here}'
>
> * * def Add(self,a,b):
> * * * * return a+b
>
> * * def Mul(self,a,b):
> * * * * return a*b
>
> if __name__ == '__main__':
> * * import win32com.server.register
> * * win32com.server.register.UseCommandLine(Example)
> ---------------------------------------------------------
>
> -------------- Excel Macro ----------------------
> Sub Testit()
> * * Set ex = CreateObject("MyPython.Example")
> * * Range("A1") = ex.Add(1, 2)
> * * Range("A2") = ex.Mul(3, 4)
> End Sub
> --------------------------------------------------------
>
> Just run the script to register the server. *"ex.py --unregister" will
> remove it.
>
> -Mark


Thanks very much. It works perfectly!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM
External inline functions calling internal inline functions Daniel Vallstrom C Programming 2 11-21-2003 01:57 PM
Re: Calling Excel module functions from python [repost] Mark Carter Python 1 07-11-2003 06:12 AM



Advertisments