Python—Excel文件xls转为xlsx
import xlrdfrom openpyxl.workbook import Workbookdef open_xls_as_xlsx(xls_path, xlsx_path):"""将 Excel中 xls 样式改为 xlsx:param xls_path: xls文件路径:param xlsx_path: xlsx文件保存路径:return:"""# first open using xlrdbook = xlrd.open_workbook(xls_path)index = 0nrows, ncols = 0, 0sheet = book.sheet_by_index(0)while nrows * ncols == 0:sheet = book.sheet_by_index(index)nrows = sheet.nrowsncols = sheet.ncolsindex += 1# prepare a xlsx sheetbook_new = Workbook()sheet_new = book_new.create_sheet("sheet1", 0)for row in range(0, nrows):for col in range(0, ncols):sheet_new.cell(row=row+1, column=col+1).value = sheet.cell_value(row, col)book_new.save(xlsx_path)