Python uses the openpyxl library to traverse Sheet examples

不言
Release: 2018-05-03 15:33:04
Original
2839 people have browsed it

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 ---')
Copy after login

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 ---')
Copy after login

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:

Analysis python uses the pickle module to complete some functions such as addition, deletion, modification and query

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template