Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Calling Python functions from Excel

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


lusvehla at gmail

Nov 14, 2009, 11:20 PM

Post #1 of 9 (326 views)
Permalink
Calling Python functions from Excel

Hi,
unfortunately is my question about server COM (win32com)
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7#
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
--
http://mail.python.org/mailman/listinfo/python-list


carsten.haese at gmail

Nov 14, 2009, 11:53 PM

Post #2 of 9 (307 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

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/pythonwin32/chapter/ch12.html (Scroll down to
"Implementing a COM Server.")

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

--
http://mail.python.org/mailman/listinfo/python-list


darcymason at gmail

Nov 16, 2009, 5:34 AM

Post #3 of 9 (295 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

On Nov 15, 2:20 am, Cannonbiker <lusve...@gmail.com> 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/forums/t319222-re-python-in-excel.html

Check from around message 3 on.
--
http://mail.python.org/mailman/listinfo/python-list


chris at simplistix

Nov 17, 2009, 3:36 AM

Post #4 of 9 (290 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

Cannonbiker wrote:
> Hi,
> unfortunately is my question about server COM (win32com)
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7#
> 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

--
http://mail.python.org/mailman/listinfo/python-list


metolone+gmane at gmail

Nov 17, 2009, 8:23 AM

Post #5 of 9 (291 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

"Chris Withers" <chris [at] simplistix> wrote in message
news:4B028AC1.8020307 [at] simplistix
> Cannonbiker wrote:
>> Hi,
>> unfortunately is my question about server COM (win32com)
>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7#
>> 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


--
http://mail.python.org/mailman/listinfo/python-list


chris at simplistix

Nov 17, 2009, 8:40 AM

Post #6 of 9 (291 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


metolone+gmane at gmail

Nov 17, 2009, 6:09 PM

Post #7 of 9 (282 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

"Chris Withers" <chris [at] simplistix> wrote in message
news:4B02D1E3.6080308 [at] simplistix
> 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


--
http://mail.python.org/mailman/listinfo/python-list


ethan at stoneleaf

Nov 17, 2009, 6:33 PM

Post #8 of 9 (283 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

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 :D
--
http://mail.python.org/mailman/listinfo/python-list


lusvehla at gmail

Nov 18, 2009, 10:38 AM

Post #9 of 9 (266 views)
Permalink
Re: Calling Python functions from Excel [In reply to]

On 18 lis, 03:09, "Mark Tolonen" <metolone+gm...@gmail.com> wrote:
> "Chris Withers" <ch...@simplistix.co.uk> wrote in message
>
> news:4B02D1E3.6080308 [at] simplistix
>
> > 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!!! :-)
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.