title: Shift cells upward- Apache POI Get t
body: <p>I'm using Apache POI XSSF to get the columns and rows from the <code>JTable</code> and create an excel file. I'm trying to separate the table according to the values of a column called &quot;Name&quot; and each name has a different sheet.</p>
  <p>And my problem is, when I try to separate them, the other sheets generate blank cells on top, the number of blank cells depends on the number of records that are above them. Here is my code:</p>
  <pre><code>//Create a blank sheet
  XSSFSheet sheet_Mark = workbook.createSheet(&quot;Mark&quot;);
  XSSFSheet sheet_John = workbook.createSheet(&quot;John&quot;);
  
  for(int i = 0; i &lt; jTable1.getRowCount(); i++){
      Integer id_Values = (int) jTable1.getValueAt(i,0);
      String name_Values = (String) jTable1.getValueAt(i, 1);
      Integer age_Values = (int) jTable1.getValueAt(i,2);
      if(name_Values.equals(&quot;Mark&quot;)){
          XSSFRow row = sheet_Mark.createRow(i);
          row.createCell(0).setCellValue(id_Values);
          row.createCell(1).setCellValue(name_Values);
          row.createCell(2).setCellValue(age_Values);
      }
      else if(name_Values.equals(&quot;John&quot;)){
          XSSFRow row = sheet_John.createRow(i);
          row.createCell(0).setCellValue(id_Values);
          row.createCell(1).setCellValue(name_Values);
          row.createCell(2).setCellValue(age_Values);
      }
  }
  </code></pre>
  <p>Here's the output of the sheets. Assuming I have 5 records on my <code>JTable</code>, 3 Johns and 2 Marks respectively:</p>
  <pre class="lang-none prettyprint-override"><code>Sheet 1:
  rows |     ID     |    Name    |     Age 
   1        1111        John           23
   2        2222        John           20
   3        3333        John           26
  
  Sheet 2:
   rows |     ID     |    Name    |     Age 
    1                                 
    2        
    3
    4        4444       Mark            45
    5        5555       Mark            30
  
      
  </code></pre>
  <p>I'm pretty much new to Java so please bear with me. I'd appreciate any answers or solutions.</p>
  <p>Edit: I know it has something to do with this line:</p>
  <pre><code>XSSFRow row = sheet_Mark.createRow(i);
  </code></pre>
  <p>Maybe if I could get the number of rows above Mark and subtract it to <code>i</code>. I really tried searching for solutions but I could not find any.</p>