0

While parsing an excel file for the values in the column with the formula format I receive null. Here is my code:

  Cell cell = row.getCell(i);
          CellValue cellValue = evaluator.evaluate(cell);
          switch(cell.getCellType())
          {
            case Cell.CELL_TYPE_NUMERIC:
                returnedMap.put(arrayForMappingNames[index], ""+cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING:
                returnedMap.put(arrayForMappingNames[index], cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA : 
                returnedMap.put(arrayForMappingNames[index], cellValue.getStringValue());
                break;
            default : 
                returnedMap.put(arrayForMappingNames[index], ExcellUtil.DEFAULT_VALUE);
          }
  • Please check https://stackoverflow.com/questions/7608511/java-poi-how-to-read-excel-cell-value-and-not-the-formula-computing-it – Sukhpal Singh Nov 11 '18 at 13:51
  • 2
    So seems your `cellValue` is not of type string. But why doing it that complicated at all? Why not using `DataFormatter`? `... DataFormatter formatter = new DataFormatter(); ... Cell cell = row.getCell(i); returnedMap.put(arrayForMappingNames[index], formatter.formatCellValue(cell, evaluator)); ...` So the whole switch case of cell types is not necessary. – Axel Richter Nov 11 '18 at 13:55

1 Answers1

0

Thanks to Alex Richter, my problem is solved now.

          Cell cell = row.getCell(i);
          CellValue cellValue = evaluator.evaluate(cell);
          String columnValue = formatter.formatCellValue(cell, evaluator);
          returnedMap.put(arrayForMappingNames[index], columnValue);