Excel Interop in Rhino 8 Script Editor (Python 2)

I am having trouble with the new script editor, running below code gives an error in Rhino 8 while it runs fine in Rhino 7? Any ideas?

The error: IOError: System.IO.IOException: Could not add reference to assembly Microsoft.Office.Interop.Excel

#! python 2
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
from Microsoft.Office.Interop import Excel

Found a fix here, apperently this has to do with the new .Net Core 7 versus .Net 4.2 in Rhino 7.

Another fix is to use clr.AddReferenceToFileAndPath("path_to_dll_file"). This does work with the new .NET Core 7 of Rhino 8.

For some reason using clr.AddReference() does not find the Windows Assembly folder containing the .dll files for Interop Assemblies (such as Office, etc.)

1 Like

Hi there. I tried the method you mentioned in Rhino 8 (python 3) but it says the Name Attribute module ā€˜clrā€™ has no attribute ā€˜AddReferenceToFileAndPathā€™. Itā€™s not working actually

@Amir_Gabrielli The clr module in Python 3 does not have the AddReferenceToFileAndPath method (IronPython 2 does).

Use clr.AddReference and provide the full dll path as input argument

I tried to do that but I failed. Iā€™m not sure which part Iā€™m doing wrong. Iā€™m trying to import Excel Application Class as shown in the picture below but in Rhino 8 the old method is not working.

It might be because you are trying via grasshopper python? My solution worked with rhino ironpython directly.

Yes Iā€™m working within grasshopper so Iā€™m using python 3 to import Excel Application Class

C:\Windows\assembly\Microsoft.Office.Interop.Excel is not a file path. Add the .dll to the end:

C:\Windows\assembly\Microsoft.Office.Interop.Excel.dll

I also tried that but itā€™s having trouble finding such a file and it gives the following error.