Re: Calling Python functions from Excel

2009-11-18 Thread Cannonbiker
On 18 lis, 03:09, "Mark Tolonen"  wrote:
> "Chris Withers"  wrote in message
>
> news:4b02d1e3.6080...@simplistix.co.uk...
>
> > 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


Re: Calling Python functions from Excel

2009-11-17 Thread Ethan Furman

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


Re: Calling Python functions from Excel

2009-11-17 Thread Mark Tolonen


"Chris Withers"  wrote in message 
news:4b02d1e3.6080...@simplistix.co.uk...

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


Re: Calling Python functions from Excel

2009-11-17 Thread Chris Withers

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


Re: Calling Python functions from Excel

2009-11-17 Thread Mark Tolonen


"Chris Withers"  wrote in message 
news:4b028ac1.8020...@simplistix.co.uk...

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


Re: Calling Python functions from Excel

2009-11-17 Thread Chris Withers

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


Re: Calling Python functions from Excel

2009-11-16 Thread Darcy Mason
On Nov 15, 2:20 am, 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.

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


Re: Calling Python functions from Excel

2009-11-14 Thread Carsten Haese
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


Calling Python functions from Excel

2009-11-14 Thread Cannonbiker
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