title: Cannot perform runtime binding on a null reference - Empty Excel Cells
body: <p>I cannot seem to think of a way to correct the error mentioned in the title and was looking for some ideas on what should be done.</p>
  
  <p>I am trying to read the rows of a excel spreadsheet into an object.</p>
  
  <p>The first time it loops I have no problems because row 1, column 1 and row 1 column 2 have data in them.</p>
  
  <p>But when it gets to row 2, column 1 and row 2 column 2 it falls over with the above error because those cells in spreadsheet are "empty"</p>
  
  <p>I just cannot work out where I can put some "if null" checks in.</p>
  
  <p>Can anyone suggest how to do it please?</p>
  
  <p>Here is my code...</p>
  
  <pre><code>private static void IterateRows(Excel.Worksheet worksheet)
      {
          //Get the used Range
          Excel.Range usedRange = worksheet.UsedRange;
  
          // create an object to store the spreadsheet data
          List&lt;SPREADSHEETModel.spreadsheetRow&gt; spreadsheetrows = new List&lt;SPREADSHEETModel.spreadsheetRow&gt;();
  
          //Iterate the rows in the used range
          foreach (Excel.Range row in usedRange.Rows)
          {
              for (int i = 0; i &lt; row.Columns.Count; i++)
              {
                  spreadsheetrows.Add(new SPREADSHEETModel.spreadsheetRow()
                  {
                      col1 = row.Cells[i + 1, 1].Value2.ToString(),
                      col2 = row.Cells[i + 1, 2].Value2.ToString()
                  });
              }
          }
      }
  </code></pre>