Package org.apache.poi.ss.usermodel

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


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

      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof NumericValueEval) {
      NumericValueEval ne = (NumericValueEval) eval;
      return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof StringValueEval) {
      StringValueEval ne = (StringValueEval) 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

            // assure that the formula refers to the cell above.
            // the check below is 'deep' and involves conversion of the shared formula:
            // in the sample file a shared formula in GN1 is spanned in the range GN2:IY2,
            assertEquals(ref_noformula.formatAsString(), fmla);

            CellValue cv_noformula = evaluator.evaluate(cell_noformula);
            CellValue cv_formula = evaluator.evaluate(cell_formula);
            assertEquals("Wrong evaluation result in " + ref_formula.formatAsString(),
                    cv_noformula.getNumberValue(), cv_formula.getNumberValue());
        }
    }
View Full Code Here

          Sheet s = wb.getSheetAt(i);
          for(Row r : s) {
             for(Cell c : r) {
                if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
                    String formula = c.getCellFormula();
                    CellValue cv;
                    try {
                        cv = eval.evaluate(c);
                    } catch (Exception e) {
                        throw new RuntimeException("Can't evaluate formula: " + formula, e);
                    }
                   
                    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

    @Test
    public void bug56315() {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56315.xlsx");
        Cell c = wb.getSheetAt(0).getRow(1).getCell(0);
        CellValue cv = wb.getCreationHelper().createFormulaEvaluator().evaluate(c);
        double rounded = cv.getNumberValue();
        assertEquals(0.1, rounded, 0.0);
    }
View Full Code Here

    private void checkValue(XSSFWorkbook excel, String expect) {
        XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(excel);
        evaluator.evaluateAll();
       
        XSSFCell cell = excel.getSheetAt(0).getRow(1).getCell(1);
        CellValue value = evaluator.evaluate(cell);
       
        assertEquals(expect, value.formatAsString());
    }
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.