title: Count used cells in row using Excel Interop
body: <p>I would like to get index of last used cell in each row in worksheet. I can get last used column in whole sheet, but I have table which has different used cells in every row, like this:
  <a href="https://i.stack.imgur.com/60zZp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/60zZp.png" alt="excell sheet sample"></a></p>
  
  <p>I tried this:</p>
  
  <pre><code>var excelApp = new Excel.Application();
  var workBook = excelApp.Workbooks.Open(excelFilePath);
  Excel._Worksheet worksheet = workBook.Worksheets[worksheetName];
  
  int rowsCount = worksheet.UsedRange.Rows.Count;
  for (int i = 1; i &lt;= rowsCount; i++)
  {               
      Excel.Range range = worksheet.Rows[i];
      int lastColumn = range.Columns.Count;
      Console.WriteLine(lastColumn);         
  }
  </code></pre>
  
  <p>and I expect output:</p>
  
  <pre><code>3
  5
  2
  7
  </code></pre>
  
  <p>but actual output is:</p>
  
  <pre><code>16384
  16384
  16384
  16384
  </code></pre>
  
  <p>I use Excel Interop library. Any suggestion would be appreciated. Thanks!</p>