Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Win32com Module Problems

$
0
0

I want to convert .xls to .xlsx, so I use win32com module

this is my code:

    import os
    import win32com.client as win32
    address = address = os.getcwd()

    fname = address + "\\Bundles.xls"
    fname2 = address + "\\searchresults.xls"
    excel = win32.gencache.EnsureDispatch('Excel.Application')
    excel2 = win32.gencache.EnsureDispatch('Excel.Application')
    wb = excel.Workbooks.Open(fname)
    wb5 = excel.Workbooks.Open(fname2)

    wb.SaveAs(fname+"x", FileFormat = 51)
    wb5.SaveAs(fname2+"x", FileFormat = 51)    #FileFormat = 51 is for .xlsx extension
    wb.Close()
    wb5.Close()                               #FileFormat = 56 is for .xls extension
    excel.Application.Quit()
    excel2.Application.Quit()
    print('File .xls convert .xlsx successful!!')

then I got the error,here it is the traceback:

Traceback (most recent call last): File "c:/Users/shenshuaic/Desktop/SFP Program/win32test.py", line 7, in excel = win32.gencache.EnsureDispatch('Excel.Application') File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch disp = win32com.client.Dispatch(prog_id) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client__init__.py", line 96, in Dispatch return WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client__init.py", line 37, in __WrapDispatch klass = gencache.GetClassForCLSID(resultCLSID) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client\gencache.py", line 183, in GetClassForCLSID mod = GetModuleForCLSID(clsid) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client\gencache.py", line 226, in GetModuleForCLSID mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\site-packages\win32com\client\gencache.py", line 266, in GetModuleForTypelib AddModuleToCache(typelibCLSID, lcid, major, minor) File "C:\Users\shenshuaic\AppData\Roaming\Python\Python37\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'


Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>