Do you want to call the Python code from Excel or manipulate Excel from Python? 
 It sounds like the former but if you want to do the former it'd look like 
(this is pieced together from some internal automation we have):

import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, 
Culture=neutral, PublicKeyToken=71e9bce111e9429c')

from Microsoft.Office.Interop import Excel

ex = Excel.ApplicationClass()
ex.Visible = True
ex.DisplayAlerts = False

workbook = ex.Workbooks.Open('foo.xls')

ws = workbook.Worksheets[1]

print ws.Rows[1].Value2[0,0]

from there you can explore the various worksheet objects that you get back.

If you do want to call Python from Excel you'd need to create a Com Callable 
Wrapper (CCW) in C# and expose it out to COM via the normal .NET interop 
mechanisms.  That CCW could then instantiate IronPython and call into it 
passing anything you got from Excel along the way.  Searching around the web 
for .NET CCW should probably get you the info on how to do the CCW side of 
things.  From there you just need to instantiate a PythonEngine and tell it 
what to run.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Luis Trigueiros
Sent: Friday, June 22, 2007 2:24 AM
To: [email protected]
Subject: [IronPython] Inproc COM object

Hi,

Can anyone point me in the direction of a code sample implementing a in process 
COM object in IronPython that is exposed in Excel.
I know of samples interacting with excel, but what I would like to do is 
perform Excel spreadsheet validation in python instead of VBA.

Thank you, Luis
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to