Package org.apache.poi.ss.usermodel

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


   */
  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


  public void testEvaluateSimple() {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFCell cell = sheet.getRow(8).getCell(0);
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(3.72, cv.getNumberValue(), 0.0);
  }
View Full Code Here

    // were 4 and 1, this would represent a circular reference.  Prior to v3.2 POI would
    // 'fully' evaluate ref arguments before invoking operators, which raised the possibility of
    // cycles / StackOverflowErrors.
   

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    assertTrue(cellValue.getCellType() == HSSFCell.CELL_TYPE_NUMERIC);
    assertEquals(2, cellValue.getNumberValue(), 0);
  }
View Full Code Here

   
    HSSFRow row = sheet.createRow(0);
    HSSFCell testCell = row.createCell(0);
    testCell.setCellFormula("A1");

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
View Full Code Here

    row.createCell(1).setCellFormula("C1");
    row.createCell(2).setCellFormula("D1");
    HSSFCell testCell = row.createCell(3);
    testCell.setCellFormula("A1");

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
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());
    }
    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

   */
  private CellValue evaluateFormulaCellValue(Cell cell) {
    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

      }
      if(isIgnoredFormulaTestCase(c.getCellFormula())) {
        continue;
      }

      CellValue actualValue;
      try {
        actualValue = evaluator.evaluate(c);
      } catch (RuntimeException e) {
        _evaluationFailureCount ++;
        printShortStackTrace(System.err, e);
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.