Is there any method to get the number of rows and columns present in .xlsx sheet using openpyxl?

Kulkarni Sachin picture Kulkarni Sachin · Feb 15, 2016 · Viewed 43.7k times · Source

Is there any method to get the number of rows and columns present in .xlsx sheet using openpyxl ? In xlrd,

     sheet.ncols 
     sheet.nrows

would give the column and row count. Is there any such method in openpyxl ?

Answer

Alexander Craggs picture Alexander Craggs · Feb 15, 2016

Given a variable sheet, determining the number of rows and columns can be done in one of the following two ways:

Version 1.x.x Syntax

rows = sheet.nrows
columns = sheet.ncols

Version 0.x.x Syntax

rows = sheet.max_row
columns = sheet.max_column