title: How to count rows per worksheet in OpenXML
body: <p>I switched from <code>Interop</code> library to <code>OpenXML</code>, because I need to read large <code>Excel</code> files. Before that I could use:</p>
  
  <pre><code>worksheet.UsedRange.Rows.Count
  </code></pre>
  
  <p>to get the number of rows with data on the worksheet. I used this information to make a progressbar. In OpenXML I do not know how to get the same information about the worksheet. What I have now is this code:</p>
  
  <pre><code> using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(path, false))
  {
      WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
      WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
      SheetData sheetData = worksheetPart.Worksheet.Elements&lt;SheetData&gt;().First();
      int row_count = 0, col_count;
      // here I would like to get the info about the number of rows
      foreach (Row r in sheetData.Elements&lt;Row&gt;())
      {
          col_count = 0;
          if (row_count &gt; 10)
          {
              foreach (Cell c in r.Elements&lt;Cell&gt;())
              {
                  // do some stuff  
                  // update progressbar  
              }
          }
          row_count++;
      }
  }
  </code></pre>