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
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
> 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.
The book Python: Programming on Win32 has a whole chapter on COM, and a
section on COM servers.
-Mark
...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
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
+1 QOTW :D
Thanks very much. It works perfectly!!! :-)