title: Finding end of file in spreadsheets
body: <p>Is there an easy way to tell when youve reached the end of a spreadsheet file when working with openpyxl? Or does someone have an easy idea how to code this task in Python3? I'm working on a program that iterates through rows, selects &amp; rewrites certain data. I want the program to be able to jump out of the loop on its own without having to input a number at the beginning.</p>
  
  <p>Currently, I'm just using the following loop but it only works because I know the file ends at line 49:</p>
  
  <pre><code>while i &lt;=50:
  </code></pre>
  
  <p>I was considering something that would check for several blank lines in a row, like this piece of code, to start the loop but it seems very imperfect:</p>
  
  <pre><code>while sheet["A"+str(i)].value!=0 and sheet["A"+str(i+1)].value!=0 and sheet["A"+str(i+2)].value!=0: 
  </code></pre>
  
  <p>Any suggestions would be helpful.</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>The easy answer is:</p>
  
  <p><code>lastrow=sheet.max_row</code></p>
  
  <p>The counter in the loop can then be set to terminate at <code>lastrow</code>.</p>
  
  <p>Thanks for your input Roland. </p>
  
  <p>Unfortunately the documentation for openpyxl I have been utilizing does not list this function, Charlie. </p>