Class ExcelComparator


  • public class ExcelComparator
    extends Object
    Utility to compare Excel File Contents cell by cell for all sheets.

    This utility will be used to compare Excel File Contents cell by cell for all sheets programmatically.

    Below are the list of Attribute comparison supported in this version.

    • Cell Alignment
    • Cell Border Attributes
    • Cell Data
    • Cell Data-Type
    • Cell Fill Color
    • Cell Fill pattern
    • Cell Font Attributes
    • Cell Font Family
    • Cell Font Size
    • Cell Protection
    • Name of the sheets
    • Number of Columns
    • Number of Rows
    • Number of Sheet

    (Some of the above attribute comparison only work for *.xlsx format currently. In future it can be enhanced.)

    Usage:

     
      Workbook wb1 = WorkbookFactory.create(new File("workBook1.xls"));
      Workbook wb2 = WorkbookFactory.create(new File("workBook2.xls"));
      List<String> listOfDifferences = ExcelComparator.compare(wb1, wb2);
      for (String differences : listOfDifferences)
          System.out.println(differences);
      System.out.println("DifferenceFound = "+ excelFileDifference.isDifferenceFound);
      
     
    • Constructor Detail

      • ExcelComparator

        public ExcelComparator()
    • Method Detail

      • compare

        public static List<String> compare​(Workbook wb1,
                                           Workbook wb2)
        Utility to compare Excel File Contents cell by cell for all sheets.
        Parameters:
        wb1 - the workbook1
        wb2 - the workbook2
        Returns:
        the Excel file difference containing a flag and a list of differences