使用win32com库python的无效类字符串

时间:2018-09-25 11:43:56

标签: python

我编写了以下流程以分发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。

1 个答案:

答案 0 :(得分:0)

对我来说很好。从站点程序包中删除pywin32,然后尝试从以下URL安装pywin32.exe:

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