how to convert xls to xlsx

前端 未结 14 1296
生来不讨喜
生来不讨喜 2020-11-27 03:58

I have some *.xls(excel 2003) files, and I want to convert those files into xlsx(excel 2007).

I use the uno python package, when I save the documents, I can set the

14条回答
  •  -上瘾入骨i
    2020-11-27 04:36

    You need to have win32com installed on your machine. Here is my code:

    import win32com.client as win32
    fname = "full+path+to+xls_file"
    excel = win32.gencache.EnsureDispatch('Excel.Application')
    wb = excel.Workbooks.Open(fname)
    
    wb.SaveAs(fname+"x", FileFormat = 51)    #FileFormat = 51 is for .xlsx extension
    wb.Close()                               #FileFormat = 56 is for .xls extension
    excel.Application.Quit()
    

提交回复
热议问题