0

Some cells have data concatenated from other cells. In trying to write a csv file from the parent file, some cells are written to the csv file by their formula not, the value of said formula. I need the resulting value, not the formula itself.

user3377627
  • 363
  • 3
  • 7
  • 22

1 Answers1

0

Try this:

private Object getCellValue(HSSFCell cell) {
    if (cell == null) { return null; }
    if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        switch (cell.getCachedFormulaResultType()) {
            case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue();
            case Cell.CELL_TYPE_STRING: return cell.getStringCellValue().replaceAll("'", "");
        }
    }
    return null;
}
Thiêm
  • 155
  • 8