title: Estimate the number of rows in an Excel file quickly
body: <p>I've got a Ruby + Merb webapp that needs to quickly estimate (or count exactly) how many row a spreadsheet has. It accepts every format that the <a href="http://roo.rubyforge.org/" rel="nofollow noreferrer">roo</a> library supports, including .xls, .xlsx, .ods, and text-based formats like CSV and TSV.</p>
  
  <p>CSV/TSV is easy and fast:</p>
  
  <pre><code>`cat #{filepath} | dos2unix | wc -l`.to_i
  </code></pre>
  
  <p>However, using the roo library can be very slow for large files:</p>
  
  <pre><code>e = Excel.new(filepath)
  e.last_row
  </code></pre>
  
  <p>My experience with Excel file formats is nil, so I'm appealing to the S.O. Masses: how might I try to estimate the number of rows an XLS, XLSX, or ODS file contains using only Ruby and/or standard UNIX programs? My goal is to be able to handle 5mb files in under 1.5 seconds (give or take on various hardware).</p>