Beg*_*udy 5 .net com ironpython
在Cpython中,我可以使用win32com.
但是,在ironpython中,我不知道如何导入它.
因为,在.net中,总是使用Visual Studio来交互COM并使用它.
您应该能够使用以下方法创建IDispatch对象:
from System import Type, Activator
Activator.CreateInstance(Type.GetTypeFromProgID(com_type_name))
Run Code Online (Sandbox Code Playgroud)
这相当于win32com.client.Dispatch(com_type_name).
如果有一个类型库你应该能够:
import clr
import System
typelib = clr.LoadTypeLibrary(System.Guid("00020905-0000-0000-C000-000000000046"))
word = typelib.Word.Application()
Run Code Online (Sandbox Code Playgroud)
我不知道那相当于什么.我不是这方面的专家,但我从IronPython的cominterop_util中获取了这些用于测试.IronPython\Tests\interop\com目录中有更多内容可能有用.