Q:

Writing HashMap to Excel

my requirement is to write a HashMap into an excel using Apache POI, the key in the hashmap is my cell-id and the value in the hashmap is the value to be set into that cell. 
Below is my code:
public static final String[] ExcelColumns = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
    "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", 
    "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", 
    "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS",
    "BT", "BU", "BV", "BW", "BX", "BY", "BZ", "CA", "CB", "CC", "CD", "CE", "CF", "CG", "CH", "CI", "CJ", "CK", "CL", "CM",
    "CN", "CO", "CP", "CQ", "CR", "CS", "CT", "CU", "CV", "CW", "CX", "CY", "CZ", "DA", "DB", "DC", "DD", "DE", "DF", "DG",
    "DH", "DI", "DJ", "DK", "DL", "DM", "DN", "DO", "DP", "DQ", "DR", "DS", "DT", "DU", "DV", "DW", "DX", "DY", "DZ"};

public static int row(Map.Entry pair) {
        //System.out.println("The row is:"+k);
        return new Integer(pair.getKey().toString().substring(1));
              }
public static int column(Map.Entry pair) {
        String indexVal = pair.getKey().toString().substring(0, 1);
        String[] ExcelColumns = CompareExcelDAO.ExcelColumns;
        int index = 0;
        for (int i = 0; i < ExcelColumns.length; ++i) {
              if (indexVal.equals(ExcelColumns[i])) {
                    index = i;
              }
        }
        return index+1;
  }
public void CopyContentsOfExcel(HSSFWorkbook workbook, HSSFSheet sheet,
              String ExcelPath_1, int i, HashMap getMismatchMap)
              throws IOException {          
        int rownum = sheet.getLastRowNum()+2; // to check last used row in Excel            
        //CompareExcelDAO mapDao = new CompareExcelDAO();
              Iterator it1 = getMismatchMap.entrySet().iterator();
              while (it1.hasNext()) {
                    Map.Entry pair = (Map.Entry) it1.next();
                    int r = row(pair) + rownum;
                    int c= column(pair);
                    System.out.println("c = "+c+"     r = "+r);
                    System.out.println("Key: "+pair.getKey()+" "+"Value: "+pair.getValue());
                    sheet.createRow(r).createCell(c).setCellValue(pair.getValue().toString());

              }}

The problem is its printing only one pair of key/value into two fixed cells, in Debug mode all the row/column values are displayed as expected however when I open the sheet only one value is printed.
http://www.tagwith.com/question_1103031_printing-a-hashmap-to-excel-using-jxl-api, this site provides a way to write Hashmap to Excel using jxl however all my project is using Apache POI.

A:

If you are want to compare two excels and write difference in third,
Create a new workbook and sheet and pass it to a method where you can open your two excels and compare something like below:
while (file1cellIterator.hasNext()&& file2cellIterator.hasNext()) {
                Cell file1cell = (Cell) file1cellIterator.next();
                Cell file2cell = (Cell) file2cellIterator.next();

                org.apache.poi.ss.usermodel.Cell cell = row.createCell(cellnum++);

                switch (file1cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:
                    if ((file1cell.getBooleanCellValue())==(file2cell.getBooleanCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue(file1cell.getBooleanCellValue());
                            }
                    else if((file1cell.getBooleanCellValue())!=(file2cell.getBooleanCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue(file1cell.getBooleanCellValue());
                    }
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    if ((file1cell.getNumericCellValue())==(file2cell.getNumericCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue(file1cell.getNumericCellValue());
                                                        }
                    else if((file1cell.getNumericCellValue())!=(file2cell.getNumericCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue((file1cell.getNumericCellValue())-(file2cell.getNumericCellValue()));
                                                }
                    break;
                case Cell.CELL_TYPE_STRING:
                    if ((file1cell.getStringCellValue())==(file2cell.getStringCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue(file1cell.getStringCellValue());
                            }
                    else if((file1cell.getStringCellValue())!=(file2cell.getStringCellValue())){
                        ((org.apache.poi.ss.usermodel.Cell) cell).setCellValue((file1cell.getStringCellValue())+(file2cell.getStringCellValue()));
                    }
                    break;
                default:
                    ((org.apache.poi.ss.usermodel.Cell) cell)
                            .setCellValue(file1cell.getStringCellValue());
                    break;
                }
            }
        }

