csv TypeError:此COM对象无法自动执行makepy过程-请为此对象手动运行makepy

dzhpxtsq  于 2022-12-06  发布在  其他
关注(0)|答案(5)|浏览(238)

这种错误究竟是什么呢?
追溯错误

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')

我正在使用PyCharmVirtualEnv

我没有找到任何解决办法,有没有人对此有想法?
注意:我曾经试图使用win32访问excel工作簿,以便能够修改它!!。

hpcdzsge

hpcdzsge1#

遇到了相同的问题,通过关闭所有正在运行的Excel应用程序解决了该问题。

brjng4g3

brjng4g32#

我遇到了同样的问题......在我的案例中,通过添加以下两行代码解决了该问题:

workbook.Close(SaveChanges=True)
xl.Quit()
cgvd09ve

cgvd09ve3#

如果在示例中多次运行excel = win32.gencache.EnsureDispatch('Excel.Application')行(也称为For循环),也会出现问题。

zpgglvta

zpgglvta4#

在我的例子中,我在不同的线程上使用事件,我忘记了将coinit_flags设置为零,例如:

# ...
import sys
sys.coinit_flags = 0  # pythoncom.COINIT_MULTITHREADED == 0
from win32com.client import *
from win32com.client.connect import *
# ...
m528fe3b

m528fe3b5#

您必须考虑从虚拟环境中运行代码。
并卸载环境之外的任何其他pywin 32模块。
给予看!

相关问题