comtypes
comtypes copied to clipboard
Not having Microsoft Office throws an obscure error when attempting at creating an Excel object
This piece of code:
from comtypes.client import CreateObject
comInstance = CreateObject('Excel.Application', dynamic = True)
when not having Microsoft Office (Excel) installed, throws the following error:
Traceback (most recent call last):
File "comErrorTest.py", line 2, in <module>
comInstance = CreateObject('Excel.Application', dynamic = True)
File "C:\ProgramData\Miniconda3\lib\site-packages\comtypes\client\__init__.py", line 227, in CreateObject
clsid = comtypes.GUID.from_progid(progid)
File "C:\ProgramData\Miniconda3\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
_CLSIDFromProgID(str(progid), byref(inst))
File "_ctypes/callproc.c", line 920, in GetResult
OSError: [WinError -2147221005] Invalid class string
I was setting up a Windows Server virtual machine on Azure and I was executing some python code that always worked on my machine (Windows 10 + Excel).
It may be worth mentioning the previous scenario somewhere in the docs.
It took me a while to figure out why that piece of code that "always worked" was not working anymore on a different machine. I am not used to Windows products and that error message was a bit obscure for the first few minutes.
It would be more accurate to say something like Class string not found
, but this is a Windows COM error, not a comtypes error, so I assume this is just how Windows COM works when it can't find the progid
. I agree the documentation for COM in general is very poor (which ironically is why I'm browsing the github issues right now!). Perhaps the error could be caught and re-thrown inside of comtypes so it could provide additional information.
@tappoz @jesse-git
I recognize that this is a matter of environment and privilege.
If the issue remains, please re-open.