1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python---Excel文件xls格式转为xlsx格式

Python---Excel文件xls格式转为xlsx格式

时间:2019-10-29 02:59:40

相关推荐

Python---Excel文件xls格式转为xlsx格式

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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。