# Comparing two excel sheets using Selenium WebDriver with Java using Apache POI

Dear All. I have two excel work books to compare. Each excel has more than 10 columns.

If the value in Cell 1 of Column A in Sheet 1 IS EQUAL TO the value in Cell 1 of Column A in sheet 2 then I have to check Cell 1 of Column B in sheet 1 with Cell 1 of Column B in sheet 2 and so on.

If the value in Cell 1 of Column A in Sheet 1 IS NOT EQUAL TO the value in Cell 1 of Column A in Sheet 2 then i have to check the value of Cell 1 of Column A in Sheet 1 with Cell 2 of Column A in Sheet 2 and so on.

Have to display the mismatched values in another sheet or highlight the mismatched row.

Kindly provide a sample code for this.

Also i have another doubt. Could you please guide me on how to get the length of a value in a particular cell of an excel sheet. Eg. I would like to get a value of Cell 1, Row 2 then i can use System.out.println(“required cell”). its working fine for me. If i would like to get the length of that cell, how to get it.

Sample Code of mine:

FileInputStream f1 = new FileInputStream(“D://Excel1.xls”);

FileInputStream f2 = new FileInputStream(“D://Excel2.xls”);

Workbook wb1 = WorkbookFactory.create(f1);

Sheet sh1 = wb1.getSheet(“Sheet1″);

Workbook wb2 = WorkbookFactory.create(f2);

Sheet sh2 = wb2.getSheet(“Sheet2″);

for (int i = 2; i<7; i++){

Row row1=sh1.getRow(i);

Cell cell1 = row1.getCell(6);

System.out.println(cell1);{

for (int j = 5; j<10; j++){

Row row2=sh2.getRow(j);

Cell cell2 = row2.getCell(26);

System.out.println(cell2);

//Above syso will display the value of that cell. How to get the length of that cell.

if(cell1 == cell2){

System.out.println(“True”);

}else{

System.out.println(“False”);

}

Thanks in advance.

Raj.

Bheem Reddy

probably you can put the cell values in String variables and compare for easy access.