Example usage for org.apache.poi.hssf.usermodel HSSFFormulaEvaluator evaluateInCell

List of usage examples for org.apache.poi.hssf.usermodel HSSFFormulaEvaluator evaluateInCell

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFormulaEvaluator evaluateInCell.

Prototype

@Override
    public HSSFCell evaluateInCell(Cell cell) 

Source Link

Usage

From source file:cdc.impl.datasource.office.ExcelDataSource.java

License:LGPL

private static String decodeValue(HSSFCell cell, HSSFFormulaEvaluator evaluator) throws RJException {
    if (cell == null) {
        return "";
    }/*ww  w  .  j  a  va  2 s  .co m*/
    switch (evaluator.evaluateInCell(cell).getCellType()) {
    case HSSFCell.CELL_TYPE_BLANK:
        return "";
    case HSSFCell.CELL_TYPE_BOOLEAN:
        return String.valueOf(cell.getBooleanCellValue());
    case HSSFCell.CELL_TYPE_ERROR:
        return "";
    case HSSFCell.CELL_TYPE_FORMULA:
        break;
    case HSSFCell.CELL_TYPE_NUMERIC:
        if (HSSFDateUtil.isCellDateFormatted(cell)) {
            return cell.toString();
        } else {
            return formatter.format(cell.getNumericCellValue());
        }
    case HSSFCell.CELL_TYPE_STRING:
        return cell.getRichStringCellValue().getString();
    }
    throw new RJException("Error reading data from Excel input file");
}