python處理excel表格?
創(chuàng)建一個(gè)工作薄:wb = openpyxl.Workbook()新增一個(gè)sheet表單:wb.create_sheet('test_case')保存case.xlsx文件:wb.save('cases.xlsx')打開(kāi)工作簿:wb = openpyxl.load_workbook('cases.xlsx')選取表單:sh = wb['Sheet1'讀取第一行、第一列的數(shù)據(jù):ce = sh.cell(row = 1,column = 1)按行讀取數(shù)據(jù):row_data = list(sh.rows)關(guān)閉工作薄:wb.close()按列讀取數(shù)據(jù):columns_data = list(sh.columns)寫(xiě)入數(shù)據(jù)之前,該文件一定要處于關(guān)閉狀態(tài)寫(xiě)入第一行、第四列的數(shù)據(jù) value = 'result':sh.cell(row = 1,column = 4,value = 'result')獲取最大行總數(shù)、最大列總數(shù):sh.max_row、sh.max_columndel 刪除表單的用法:del wb['sheet_name'] remove 刪除表單的用法:sh = wb['sheet_name'] wb.remove(sh)