0

我编写了流程来调度一个 excel 应用程序。我在python中使用了win32库并写了这个:

import win32com.client as win32
import pywinauto

excel = win32.gencache.EnsureDispatch('Excel.Application'

由于这一行,我得到了这个错误:

K:\venv\Scripts\python.exe K:/test_results.efrat.py
Traceback (most recent call last):
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
win32.types.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "K:/test_results.efrat.py", line 8, in <module>
    excel = win32.gencache.EnsureDispatch('Excel.Application')
  File "K:\venv\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "K:\venv\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
win32.types.com_error: (-2147221005, 'Invalid class string', None, None)

Process finished with exit code 1

有谁知道可能是什么问题?我的库包中安装了 pywin32 和 pypiwin32。

4

1 回答 1

0

这对我来说可以。从站点包中删除您的 pywin32 并尝试从以下 URL 安装 pywin32.exe:

https://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/

于 2018-09-25T12:06:15.540 回答