1

I pulled the code from how to convert xls to xlsx and it worked for about 6 weeks.

Here is my implementation

import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')

Then one day it just stopped, raises this error, and doesn't get any further into my code.

Traceback (most recent call last):
  File "C:\Python\convert.py", line 32, in <module>
    excel = win32.gencache.EnsureDispatch('Excel.Application')
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch
    return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\__init__.py", line 37, in __WrapDispatch
    klass = gencache.GetClassForCLSID(resultCLSID)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\gencache.py", line 183, in GetClassForCLSID
    mod = GetModuleForCLSID(clsid)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\gencache.py", line 226, in GetModuleForCLSID
    mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\gencache.py", line 266, in GetModuleForTypelib
    AddModuleToCache(typelibCLSID, lcid, major, minor)
  File "C:\Users\jkenn\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\gencache.py", line 552, in AddModuleToCache
    dict = mod.CLSIDToClassMap
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9' has no attribute 'CLSIDToClassMap'

I am entirely self taught and this is well beyond my ability to dignose so if someone could shed some light onto why this started happening I would be very grateful.

EDIT: I found this article regarding win32com

win32.Dispatch vs win32.gencache in Python. What are the pros and cons?

I have tried both vesions and the same error appears so is there some issue with calling the 'Excel.application'?

  • seem to remember that there is a way to generate the bindings between pywin32 and the Windows API (it was a menu item on the IDE that comes with pywin?). So regenerating the bindings might be something to try. Sorry that's a bit vague, I haven't used it in a long time. – snakecharmerb Sep 13 '20 at 11:24
  • 1
    Does this answer your question? [Issue in using win32com to access Excel file](https://stackoverflow.com/questions/47608506/issue-in-using-win32com-to-access-excel-file) – Hampus Larsson Sep 13 '20 at 11:25
  • 2
    Solved it! Ill post here if anyone else runs across this issue. Answer on github [link]https://gist.github.com/rdapaz/63590adb94a46039ca4a10994dff9dbe. # If errors are found, do this # clear contents of C:\Users\\AppData\Local\Temp\gen_py – James Kennard Sep 13 '20 at 20:05

0 Answers0