Java Code Examples for org.apache.poi.ss.usermodel.Cell#getCachedFormulaResultTypeEnum()

The following examples show how to use org.apache.poi.ss.usermodel.Cell#getCachedFormulaResultTypeEnum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneClickImporterServiceImpl.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Object getTypedFormulaValue(Cell cell) {
  Object value;
  switch (cell.getCachedFormulaResultTypeEnum()) {
    case STRING:
      value = cell.getStringCellValue();
      break;
    case NUMERIC:
      value = cell.getNumericCellValue();
      break;
    case BOOLEAN:
      value = cell.getBooleanCellValue();
      break;
    case BLANK:
      value = null;
      break;
    case ERROR:
      value = "#ERROR";
      break;
    default:
      value = null;
      break;
  }
  return value;
}
 
Example 2
Source File: DataValidationEvaluator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
* Note that this assumes the cell cached value is up to date and in sync with data edits
* @param cell
* @param type
* @return true if the cell or cached cell formula result type match the given type
*/
public static boolean isType(Cell cell, CellType type) {
    final CellType cellType = cell.getCellTypeEnum();
    return cellType == type 
          || (cellType == CellType.FORMULA 
              && cell.getCachedFormulaResultTypeEnum() == type
             );
}
 
Example 3
Source File: EvaluationConditionalFormatRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ValueAndFormat getCellValue(Cell cell) {
    if (cell != null) {
        final CellType type = cell.getCellTypeEnum();
        if (type == CellType.NUMERIC || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.NUMERIC) ) {
            return new ValueAndFormat(new Double(cell.getNumericCellValue()), cell.getCellStyle().getDataFormatString());
        } else if (type == CellType.STRING || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.STRING) ) {
            return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
        } else if (type == CellType.BOOLEAN || (type == CellType.FORMULA && cell.getCachedFormulaResultTypeEnum() == CellType.BOOLEAN) ) {
            return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
        }
    }
    return new ValueAndFormat("", "");
}
 
Example 4
Source File: Cells.java    From datacollector with Apache License 2.0 5 votes vote down vote up
static Field parseCell(Cell cell, FormulaEvaluator evaluator) throws ExcelUnsupportedCellTypeException {
  CellType cellType = cell.getCellTypeEnum();
  // set the cellType of a formula cell to its cached formula result type in order to process it as its result type
  boolean isFormula = cell.getCellTypeEnum().equals(CellType.FORMULA);
  if (isFormula) {
    cellType = cell.getCachedFormulaResultTypeEnum();
  }

  switch (cellType) {
    case STRING:
      return Field.create(cell.getStringCellValue());
    case NUMERIC:
      Double rawValue = cell.getNumericCellValue();  // resolves formulas automatically and gets value without cell formatting
      String displayValue = isFormula ? evaluator.evaluate(cell).formatAsString() : dataFormatter.formatCellValue(cell);
      boolean numericallyEquivalent = false;
      try {
        numericallyEquivalent = Double.parseDouble(displayValue) == rawValue;
      } catch (NumberFormatException e) { }

      if (DateUtil.isCellDateFormatted(cell)) {
        // It's a date, not a number
        java.util.Date dt = cell.getDateCellValue();
        // if raw number is < 1 then it's a time component only, otherwise date.
        return rawValue < 1 ? Field.createTime(dt) : Field.createDate(dt);
      }

      // some machinations to handle integer values going in without decimal vs. with .0 for rawValue
      return Field.create(numericallyEquivalent ? new BigDecimal(displayValue) : BigDecimal.valueOf(rawValue));

    case BOOLEAN:
      return Field.create(cell.getBooleanCellValue());
    case BLANK:
      return Field.create("");
    default:
      throw new ExcelUnsupportedCellTypeException(cell, cellType);
  }
}
 
Example 5
Source File: SheetUtil.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** 
 * @since POI 3.15 beta 3
 * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
 */
@Internal(since="POI 3.15 beta 3")
@Override
public CellType evaluateFormulaCellEnum(Cell cell) {
    return cell.getCachedFormulaResultTypeEnum();
}
 
Example 6
Source File: CellFormat.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the ultimate cell type, following the results of formulas.  If
 * the cell is a {@link CellType#FORMULA}, this returns the result of
 * {@link Cell#getCachedFormulaResultTypeEnum()}.  Otherwise this returns the
 * result of {@link Cell#getCellTypeEnum()}.
 *
 * @param cell The cell.
 *
 * @return The ultimate type of this cell.
 * @since POI 3.15 beta 3
 * @deprecated POI 3.15 beta 3
 * Will be deleted when we make the CellType enum transition. See bug 59791.
 */
public static CellType ultimateTypeEnum(Cell cell) {
    CellType type = cell.getCellTypeEnum();
    if (type == CellType.FORMULA)
        return cell.getCachedFormulaResultTypeEnum();
    else
        return type;
}