I am trying to read an Excel file from Revit 2017 API, using Revit Python Shell. Basically, I have no idea of what I'm doing, but I tried this: http://wiki.theprovingground.org/revit-api-py-excel , but I'm getting an error:
Traceback (most recent call last): File "", line 1, in EnvironmentError: System.Runtime.InteropServices.COMException (0x800401F3): Invalid class string (Exception from HRESULT: 0x800401F3 (CO at System.Runtime.InteropServices.Marshal.CLSIDFromProgID(String progId, Guid& clsid) at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID) at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.b__0()
when running: System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')
I am doing this on a Windows 7 machine.
On side of that, I tried pretty much every module I found on the web, that are supposed to help opening xlsx files, but every time I'm getting and error at some point. Can anybody help on that? It can be ods files as well.
Thanks! Arnaud.
The code you're using (System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')
) assumes Excel is already running.
Check this page for a different approach: http://www.ironpython.info/index.php?title=Interacting_with_Excel
Basically, try this:
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
import Microsoft.Office.Interop.Excel as Excel
excel = Excel.ApplicationClass()
If you want to get an active instance (if any), you could use your first method in a try/except
block and only create a new excel instance if none is found.
Another option is to use module xlrd
- this way you won't need to have Excel installed. This question discusses some issues with using xlrd
in IronPython
Why use a proprietary file format like XLS
instead of something sensible, simple and open like CSV
?
User contributions licensed under CC BY-SA 3.0