[IronPython] Inproc COM object

Dino Viehland dinov at exchange.microsoft.com
Fri Jun 22 17:14:37 CEST 2007


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: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Luis Trigueiros
Sent: Friday, June 22, 2007 2:24 AM
To: users at lists.ironpython.com
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070622/18cd82d7/attachment.html>


More information about the Ironpython-users mailing list