This article mainly introduces the example of using Python to traverse Sheet using the openpyxl library. It has certain reference value. Now I share it with you. Friends in need can refer to the
method. First, Use sheet.iter_rows() to get all the rows in the Sheet1 table, and then traverse
import openpyxl wb = openpyxl.load_workbook('example.xlsx') sheet = wb.get_sheet_by_name('Sheet1') for row in sheet.iter_rows(): for cell in row: print(cell.coordinate, cell.value) print('--- END OF ROW ---')
sheet = wb.get_sheet_by_name('Sheet1') for rowOfCellObjects in sheet['A1':'C3']: for cellObj in rowOfCellObjects: print(cellObj.coordinate, cellObj.value) print('--- END OF ROW ---')
Method 2, Use sheet.max_row sheet.max_colum to get the value of the largest row and column in the Sheet1 table, and then traverse
Related recommendations:
The above is the detailed content of Python uses the openpyxl library to traverse Sheet examples. For more information, please follow other related articles on the PHP Chinese website!