how to convert xls to xlsx

前端 未结 14 1330
生来不讨喜
生来不讨喜 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
    慢半拍i (楼主)
    2020-11-27 04:55

    Try using win32com application. Install it in your machine.

    import sys, os
    import win32com.client
    directory = 'C:\\Users\\folder\\'
    for file in os.listdir(directory):
        dot = file.find('.')
        end = file[dot:]
        OutFile =file[0:dot] + ".xlsx"
        App = win32com.client.Dispatch("Excel.Application")
        App.Visible = True
        workbook= App.Workbooks.Open(file)
        workbook.ActiveSheet.SaveAs(OutFile, 51)   #51 is for xlsx 
        workbook.Close(SaveChanges=True)
        App.Quit()
    

    Thank you.

提交回复
热议问题