'invalid class string using win32com library python
I wrote the flowing to dispatch an excel application. I used the win32 library in python and wrote this:
import win32com.client as win32
import pywinauto
excel = win32.gencache.EnsureDispatch('Excel.Application'
Because of this line i got this error:
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
Does anyone know what could be the problem? I have pywin32 and pypiwin32 installed in my library packages.
Solution 1:[1]
It works fine for me. Remove your pywin32 from site-packages and try installing the pywin32.exe from the following URL :
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vijay Lingam |