python中xls转为xlsx

def convert_to_xlsx(file_path):
    excel_app = win32.Dispatch("Excel.Application")
    file_xlsx = file_path.replace(".xls", ".xlsx")

    excel_app.Visible = False
    excel_app.DisplayAlerts = False

    workbook = excel_app.Workbooks.Open(os.path.abspath(file_path))
    # 51 refers to the .xlsx format in VBA
    workbook.SaveAs(os.path.abspath(file_xlsx), FileFormat=51)  
    workbook.Close()
    excel_app.Quit()

    return file_xlsx

你可能感兴趣的:(python)