title: How to get the row with the actual index while iterator skips rows that are null
body: <p>I am using apache poi to parse a set of excel files. They all look like this.</p>
  
  <p><a href="https://i.stack.imgur.com/RKzke.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RKzke.png" alt="enter image description here"></a></p>
  
  <p>My code is supposed to find the ID row and then locate the two rows before it in order to extract the content of the first cell of that row. </p>
  
  <p>The code is as follows:</p>
  
  <pre><code>            Iterator&lt;Row&gt; rowIterator = sheet.iterator();
              int rowIndex = 0;
              while (rowIterator.hasNext())
              {
                  row = rowIterator.next();
                  rowIndex ++;
                  cell = row.getCell(0);
                  if (cell != null) {
                      if (rowIndex &gt; 2) {
                        Row protocolRow = sheet.getRow(rowIndex - 3);
                        String cellStr = protocolRow.getCell(0).getStringValue();
                      }
                  }
              }
  </code></pre>
  
  <p>While the relative position of the two rows is fixed, index in method getRow(index) is the absolute row index of the spreadsheet. There are a lot of empty rows in the spreadsheet. Some of them may be null others may not be. Since row iterator skips the ones that are null, rowIndex is not the counter for absolute index. Also Iterator can not go back to get previous rows. What is the best row to obtain the absolute row index of the row that is two rows before the ID row?</p>