title: Compare 2 Excel data if same column name having different postion
body: <p>I want to compare two excel sheet data with same column name, excel sheet having same column name but position of column name will be different. So, I need logic first check column name and compare data</p>
  <p>below code is working if both the sheet column name have same position or index.</p>
  <p>public static void main(String[] args) throws IOException {</p>
  <pre><code>    // Workbook1 Code
      
      FileInputStream filepath1 = new FileInputStream(&quot;.\\DataFile\\Book1.xlsx&quot;);
  
      XSSFWorkbook workbook1 = new XSSFWorkbook(filepath1);
  
      XSSFSheet worksheet1 = workbook1.getSheet(&quot;sheet1&quot;);
  
      int rowcount1 = worksheet1.getPhysicalNumberOfRows();
      int CellCount=worksheet1.getRow(0).getPhysicalNumberOfCells();
  
  
      System.out.println(&quot;row count of worbook1:&quot; + rowcount1);
  
      // Workbook2 Code
  
      FileInputStream filepath2 = new FileInputStream(&quot;.\\DataFile\\Book2.xlsx&quot;);
  
      XSSFWorkbook workbook2 = new XSSFWorkbook(filepath2);
  
      XSSFSheet worksheet2 = workbook2.getSheet(&quot;sheet1&quot;);
  
      int rowcount2 = worksheet2.getPhysicalNumberOfRows();
  
      System.out.println(&quot;row count of worbook2:&quot; + rowcount2);
  
      if (rowcount1 == rowcount2) // condition if rowcount1 is equal to row count of worbook2 are same
      {
          for (int i = 0; i &lt; rowcount1; i++) {
              
              for(int j=0; j&lt;CellCount; j++)
              {
                  
              XSSFCell row1 = worksheet1.getRow(i).getCell(j);
  
              XSSFCell row2 = worksheet2.getRow(i).getCell(j);
              
              row1.setCellType(CellType.STRING);
              
              String cellvalue=row1.getStringCellValue();
              
              row2.setCellType(CellType.STRING);
              
              String cellvalue2=row2.getStringCellValue();
              
              if(!cellvalue.equals(cellvalue2))
              {
                  System.out.println(&quot;Row number:&quot;+i+ &quot;  Column number:&quot;+j+&quot; [ERROR] :&quot; + &quot;Diference in data &quot; +&quot;| Book1 id = &quot; + cellvalue + &quot; | Book2 id = &quot; + cellvalue2);
              }
              
              }}}
  </code></pre>