How can I run the hosted version of ironpython 1.1 from an Excel add-in?
I'm writing an Excel add-in that hosts IronPython 1.1, and I want to expose an Excel.Application COM object to a PythonEngine instance.
My C # can easily access the members of a COM object. However, when my IronPython script accesses the members of a COM object, I get "System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.UInt32 &'."
Here is my C # code containing IronPython 1.1:
public void ExecuteFile(string path) {
// see if COM object works
Debug.WriteLine(Globals.ThisAddIn.Application.ActiveWindow.Caption);
engine.Globals.Add("excel", Globals.ThisAddIn.Application);
try
{
engine.ExecuteFile(path);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
and here is my IronPython test script:
excel.ActiveSheet.Range['A1'].Value2 = 42
// throws the exception mentioned above
source to share
Nice article with explanation and solution here:
http://codeidol.com/csharp/c-sharp-in-office/Working-with-Excel-Objects/Special-Excel-Issues/
Basically, I decided to disable the VSTO proxy that wraps the Excel COM object. It can be done with this line in AssemblyInfo.cs:
[assembly: ExcelLocale1033 (false)]
source to share