这种错误究竟是什么呢?
追溯错误
C:\Users\DELL\PycharmProjects\MyNew\venv\Scripts\python.exe
C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py
Traceback (most recent call last):
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 530, in EnsureDispatch
ti = disp._oleobj_.GetTypeInfo()
pywintypes.com_error: (-2147418111, 'Call was rejected by callee.', None,
None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process -
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run
makepy manually for this object
Process finished with exit code 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process -
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run
makepy manually for this object
这是我的代码
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
我正在使用PyCharm
VirtualEnv
我没有找到任何解决办法,有没有人对此有想法?
注意:我曾经试图使用win32访问excel
工作簿,以便能够修改它!!。
5条答案
按热度按时间hpcdzsge1#
遇到了相同的问题,通过关闭所有正在运行的Excel应用程序解决了该问题。
brjng4g32#
我遇到了同样的问题......在我的案例中,通过添加以下两行代码解决了该问题:
cgvd09ve3#
如果在示例中多次运行
excel = win32.gencache.EnsureDispatch('Excel.Application')
行(也称为For
循环),也会出现问题。zpgglvta4#
在我的例子中,我在不同的线程上使用事件,我忘记了将
coinit_flags
设置为零,例如:m528fe3b5#
您必须考虑从虚拟环境中运行代码。
并卸载环境之外的任何其他pywin 32模块。
给予看!