我正在尝试使该程序运行。
我在Win10 Enterprise(版本10.0.17763版本Build 17763)中使用Python 3.7.2,并且系统基于64位。
我试图使其在多台PC上运行。在其中一些上,它奏效了。
import win32com.client
o = win32com.client.Dispatch("Object.Name")
o.Method()
o.property = "New Value"
print(o.property)
o.prop_map_get_.keys()
o = win32com.gencache.EnsureDispatch('Excel.Application')
o.Visible = 1
o.Workbooks.Add()
o.Cells(1, 1).Value = "Hello"
错误:
Traceback (most recent call last):
File "test.py", line 2, in <module>
o = win32com.client.Dispatch("Object.Name")
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Ungültige Klassenzeichenfolge', None, None)
答案 0 :(得分:2)
您必须禁用BIOS中的所有安全启动选项。我也有这个问题。