Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.CellValue


      case HSSFCell.CELL_TYPE_ERROR:
        return CellValue.getError(cell.getErrorCellValue());
      case HSSFCell.CELL_TYPE_FORMULA:
        return evaluateFormulaCellValue(cell);
      case HSSFCell.CELL_TYPE_NUMERIC:
        return new CellValue(cell.getNumericCellValue());
      case HSSFCell.CELL_TYPE_STRING:
        return new CellValue(cell.getRichStringCellValue().getString());
      case HSSFCell.CELL_TYPE_BLANK:
        return null;
    }
    throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
  }
View Full Code Here


   */
  public int evaluateFormulaCell(Cell cell) {
    if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
      return -1;
    }
    CellValue cv = evaluateFormulaCellValue(cell);
    // cell remains a formula cell, but the cached value is changed
    setCellValue(cell, cv);
    return cv.getCellType();
  }
View Full Code Here

    if (cell == null) {
      return null;
    }
    HSSFCell result = (HSSFCell) cell;
    if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
      CellValue cv = evaluateFormulaCellValue(cell);
      setCellValue(cell, cv);
      setCellType(cell, cv); // cell will no longer be a formula cell
    }
    return result;
  }
View Full Code Here

   */
  private CellValue evaluateFormulaCellValue(Cell cell) {
    ValueEval eval = _bookEvaluator.evaluate(new HSSFEvaluationCell((HSSFCell)cell));
    if (eval instanceof NumberEval) {
      NumberEval ne = (NumberEval) eval;
      return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
      StringEval ne = (StringEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
View Full Code Here

      case XSSFCell.CELL_TYPE_ERROR:
        return CellValue.getError(cell.getErrorCellValue());
      case XSSFCell.CELL_TYPE_FORMULA:
        return evaluateFormulaCellValue(cell);
      case XSSFCell.CELL_TYPE_NUMERIC:
        return new CellValue(cell.getNumericCellValue());
      case XSSFCell.CELL_TYPE_STRING:
        return new CellValue(cell.getRichStringCellValue().getString());
            case XSSFCell.CELL_TYPE_BLANK:
                return null;
    }
    throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
  }
View Full Code Here

   */
  public int evaluateFormulaCell(Cell cell) {
    if (cell == null || cell.getCellType() != XSSFCell.CELL_TYPE_FORMULA) {
      return -1;
    }
    CellValue cv = evaluateFormulaCellValue(cell);
    // cell remains a formula cell, but the cached value is changed
    setCellValue(cell, cv);
    return cv.getCellType();
  }
View Full Code Here

    if (cell == null) {
      return null;
    }
    XSSFCell result = (XSSFCell) cell;
    if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
      CellValue cv = evaluateFormulaCellValue(cell);
      setCellType(cell, cv); // cell will no longer be a formula cell
      setCellValue(cell, cv);
    }
    return result;
  }
View Full Code Here

        }

    ValueEval eval = _bookEvaluator.evaluate(new XSSFEvaluationCell((XSSFCell) cell));
    if (eval instanceof NumberEval) {
      NumberEval ne = (NumberEval) eval;
      return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
      StringEval ne = (StringEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
View Full Code Here

       for(int i=0; i<wb.getNumberOfSheets(); i++) {
          Sheet s = wb.getSheetAt(i);
          for(Row r : s) {
             for(Cell c : r) {
                if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
                    CellValue cv = eval.evaluate(c);
                    if(cv.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                        // assert that the calculated value agrees with
                        // the cached formula result calculated by Excel
                        double cachedFormulaResult = c.getNumericCellValue();
                        double evaluatedFormulaResult = cv.getNumberValue();
                        assertEquals(c.getCellFormula(), cachedFormulaResult, evaluatedFormulaResult, 1E-7);
                    }
                }
             }
          }
View Full Code Here

    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("1+IF(1,,)");
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
      cv = fe.evaluate(cell);
    } catch (RuntimeException e) {
      throw new AssertionFailedError("Missing arg result not being handled correctly.");
    }
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    // adding blank to 1.0 gives 1.0
    assertEquals(1.0, cv.getNumberValue(), 0.0);

    // check with string operand
    cell.setCellFormula("\"abc\"&IF(1,,)");
    fe.notifySetFormula(cell);
    cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
    // adding blank to "abc" gives "abc"
    assertEquals("abc", cv.getStringValue());
   
    // check CHOOSE()
    cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)");
    fe.notifySetFormula(cell);
    cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
    // adding blank to "abc" gives "abc"
    assertEquals("abc", cv.getStringValue());
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.CellValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.