import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class CompareTwoExcelSheets {
public Map getExcelDataInMap(String inputFileName, String sheetName)
throws IOException {
throws IOException {
LinkedHashMap<Integer, List> rowWiseDetails = new LinkedHashMap<Integer, List>();
HashMap<String, LinkedHashMap<Integer, List>> outerMap = new LinkedHashMap<String, LinkedHashMap<Integer, List>>();
InputStream fis = getClass().getResourceAsStream(inputFileName);
HashMap<String, LinkedHashMap<Integer, List>> outerMap = new LinkedHashMap<String, LinkedHashMap<Integer, List>>();
InputStream fis = getClass().getResourceAsStream(inputFileName);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheet(sheetName);
Iterator<Row> rowIt = sheet.iterator();
while (rowIt.hasNext()) {
Row row = rowIt.next();
Iterator<Cell> cellIterator = row.cellIterator();
List data = new LinkedList();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
data.add(cell.toString());
}
rowWiseDetails.put(row.getRowNum(), data);
}
return rowWiseDetails;
}
XSSFSheet sheet = workbook.getSheet(sheetName);
Iterator<Row> rowIt = sheet.iterator();
while (rowIt.hasNext()) {
Row row = rowIt.next();
Iterator<Cell> cellIterator = row.cellIterator();
List data = new LinkedList();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
data.add(cell.toString());
}
rowWiseDetails.put(row.getRowNum(), data);
}
return rowWiseDetails;
}
private void syso() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
public static void main(String[] args) {
try {
Map ss = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
Map pp = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
if (ss.equals(pp)) {
System.out.println("success!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Map ss = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
Map pp = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
if (ss.equals(pp)) {
System.out.println("success!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}