title: How can i make my code make an excel output that highlights the cells with differences
body: <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import org.apache.poi.hssf.usermodel.HSSFCell;
  import org.apache.poi.ss.usermodel.CellType;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class Execute {
  
      public static void main(String[] args) {
          try {
              // get input excel files
              FileInputStream excellFile1 = new FileInputStream(new File(
                      &quot;C:\\Users\\Leeny\\Desktop\\Teacher.xlsx&quot;));
  
              FileInputStream excellFile2 = new FileInputStream(new File(
                      &quot;C:\\Users\\Leeny\\Desktop\\Teacher1.xlsx&quot;));
  
              // Create Workbook instance holding reference to .xlsx file
              XSSFWorkbook workbook1 = new XSSFWorkbook(excellFile1);
              XSSFWorkbook workbook2 = new XSSFWorkbook(excellFile2);
  
              // Get first/desired sheet from the workbook
              XSSFSheet sheet1 = workbook1.getSheetAt(0);
              XSSFSheet sheet2 = workbook2.getSheetAt(0);
  
              // returns result of CompareTwoSheets
              if(compareTwoSheets(sheet1, sheet2)) {
  
                  System.out.println(&quot;\n\nThe two excel sheets are Equal&quot;);
              }
  
              else {
                  System.out.println(&quot;\n\nThe two excel sheets are Not Equal&quot;);
              }
  
              //close files
              excellFile1.close();
              excellFile2.close();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  
      // Compare Two Sheets
      public static boolean compareTwoSheets(XSSFSheet sheet1, XSSFSheet sheet2) {
  
          int firstRow1 = sheet1.getFirstRowNum();
          int lastRow1 = sheet1.getLastRowNum();
          boolean equalSheets = true;
  
          for(int i=firstRow1; i &lt; lastRow1; i++) {
  
              System.out.println(&quot;\n\nComparing Row &quot;+i);
  
              XSSFRow row1 = sheet1.getRow(i);
              XSSFRow row2 = sheet2.getRow(i);
  
              if(!compareTwoRows(row1, row2)) {
  
                  equalSheets = false;
                  System.out.println(&quot;Row &quot;+i+&quot; - Not Equal&quot;);
              }
  
              else {
                  System.out.println(&quot;Row &quot;+i+&quot; - Equal&quot;);
              }
          }
          return equalSheets;
      }
  
      // Compare Two Rows
      public static boolean compareTwoRows(XSSFRow row1, XSSFRow row2) {
  
          if((row1 == null) &amp;&amp; (row2 == null)) {
              return true;
          }
          else if((row1 == null) || (row2 == null)) {
              return false;
          }
  
          int firstCell1 = row1.getFirstCellNum();
          int lastCell1 = row1.getLastCellNum();
          boolean equalRows = true;
  
          // Compare all cells in a row
          for(int i=firstCell1; i &lt; lastCell1; i++) {
  
              XSSFCell cell1 = row1.getCell(i);
              XSSFCell cell2 = row2.getCell(i);
  
              if(!compareTwoCells(cell1, cell2)) {
  
                  equalRows = false;
                  System.out.println(&quot;       Cell &quot;+i+&quot; - NOt Equal&quot;);
  
              }
  
              else {
                  System.out.println(&quot;       Cell &quot;+i+&quot; - Equal&quot;);
              }
          }
          return equalRows;
      }
  
      // Compare Two Cells
      public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) {
  
          if((cell1 == null) &amp;&amp; (cell2 == null)) {
              return true;
          }
  
          else if((cell1 == null) || (cell2 == null)) {
              return false;
          }
  
          boolean equalCells = false;
          CellType type1 = cell1.getCellType();
          CellType type2 = cell2.getCellType();
  
          if (type1 == type2) {
  
              if (cell1.getCellStyle().equals(cell2.getCellStyle())) {
  
                  // Compare cells based on its type
                  switch (cell1.getCellType()) {
  
                      case FORMULA:
                          if (cell1.getCellFormula().equals(cell2.getCellFormula())) {
                              equalCells = true;
                          }
                          break;
  
                      case NUMERIC:
                          if (cell1.getNumericCellValue() == cell2
                                  .getNumericCellValue()) {
                              equalCells = true;
                          }
                          break;
  
                      case STRING:
                          if (cell1.getStringCellValue().equals(cell2
                                  .getStringCellValue())) {
                              equalCells = true;
                          }
                          break;
  
                      case BOOLEAN:
                          if (cell1.getBooleanCellValue() == cell2
                                  .getBooleanCellValue()) {
                              equalCells = true;
                          }
                          break;
  
                      case ERROR:
                          if (cell1.getErrorCellValue() == cell2.getErrorCellValue()) {
                              equalCells = true;
                          }
                          break;
                  }
              } else {
                  return false;
              }
          } else {
              return false;
          }
          return equalCells;
      }
  }
  </code></pre>