【常见问题】Python自动化办公,打开输出的word文件,报错AttributeError: module ‘win32com.gen_py.00020905-0000-0000-

Python自动化办公,打开输出的word文件,出现ERROR:

  File "D:\Develop\Building_save_energy\BuildingDiagnoseRenovationTool.py", line 2930, in open_doc
    doc_app = win32.gencache.EnsureDispatch('Word.Application')
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\gencache.py", line 621, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\__init__.py", line 119, in Dispatch
    return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\__init__.py", line 47, in __WrapDispatch
    klass = gencache.GetClassForCLSID(resultCLSID)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\gencache.py", line 200, in GetClassForCLSID
    mod = GetModuleForCLSID(clsid)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\gencache.py", line 245, in GetModuleForCLSID
    mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\gencache.py", line 287, in GetModuleForTypelib
    AddModuleToCache(typelibCLSID, lcid, major, minor)
  File "C:\Users\Jay\.conda\envs\save_energy\lib\site-packages\win32com\client\gencache.py", line 661, in AddModuleToCache
    SetTypelibForAllClsids(mod.CLSIDToClassMap)
AttributeError: module 'win32com.gen_py.00020905-0000-0000-C000-000000000046x0x8x7' has no attribute 'CLSIDToClassMap'

解决办法:
(1)找到gen_py文件夹下对应的python版本号文件夹中的00020905-0000-0000-C000-000000000046x0x8x7文件夹,然后删除,重新执行代码,打开输出的文件不再报错。
(2)gen_py文件夹的查找方法: 使用Everything.exe软件搜索,可能会出现好几个gen_py文件夹,打开C:\Users\Jay\AppData\Local\Temp\gen_py即可。

你可能感兴趣的:(【常见问题】Python自动化办公,打开输出的word文件,报错AttributeError: module ‘win32com.gen_py.00020905-0000-0000-)