Package org.apache.poi.ss.usermodel

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


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

      CellValue actualValue;
      try {
        actualValue = evaluator.evaluate(c);
      } catch (RuntimeException e) {
        _evaluationFailureCount ++;
        printShortStackTrace(System.err, e);
View Full Code Here


    cellB1.setCellValue(1.5);

    fe.notifyUpdateCell(cellA1);
    fe.notifyUpdateCell(cellB1);

    CellValue cv;
    cv = fe.evaluate(cellA1);
    assertEquals(3.7, cv.getNumberValue(), 0.0);

    cellB1.setCellType(HSSFCell.CELL_TYPE_BLANK);
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1); // B1 was used to evaluate A1
    assertEquals(2.2, cv.getNumberValue(), 0.0);

    cellB1.setCellValue(0.4)// changing B1, so A1 cached result should be cleared
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1);
    if (cv.getNumberValue() == 2.2) {
      // looks like left-over cached result from before change to B1
      throw new AssertionFailedError("Identified bug 46053");
    }
    assertEquals(2.6, cv.getNumberValue(), 0.0);
  }
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

    // put some values in the cells to make the evaluation more interesting
    sheet.createRow(32768).createCell(0).setCellValue(31);
    sheet.createRow(32769).createCell(0).setCellValue(11);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue result;
    try {
      result = fe.evaluate(cell);
    } catch (RuntimeException e) {
      FormulaParserTestHelper.confirmParseException(e);
      if (!e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) {
        throw new AssertionFailedError("Identifed bug 44539");
      }
      throw e;
    }
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, result.getCellType());
    assertEquals(42.0, result.getNumberValue(), 0.0);
  }
View Full Code Here

      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

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.