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


      Cell c = formulasRow.getCell(colnum);
      if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
        continue;
      }

      CellValue actualValue = evaluator.evaluate(c);

      Cell expectedValueCell = getExpectedValueCell(expectedValuesRow, colnum);
      try {
        confirmExpectedResult("Function '" + targetFunctionName + "': Formula: " + c.getCellFormula() + " @ " + formulasRow.getRowNum() + ":" + colnum,
            expectedValueCell, actualValue);
View Full Code Here


    cellB1.setCellValue(1.0); // range will be C1:D1

    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
      cv = fe.evaluate(cellA1);
    } catch (IllegalArgumentException e) {
      if (e.getMessage().equals("Unexpected ref arg class (org.apache.poi.ss.formula.LazyAreaEval)")) {
        throw new AssertionFailedError("Identified bug 46948");
      }
      throw e;
    }

    assertEquals(12.0, cv.getNumberValue(), 0.0);

    cellB1.setCellValue(2.0); // range will be C1:E1
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1);
    assertEquals(21.0, cv.getNumberValue(), 0.0);

    cellB1.setCellValue(0.0); // range will be C1:C1
    fe.notifyUpdateCell(cellB1);
    cv = fe.evaluate(cellA1);
    assertEquals(5.0, cv.getNumberValue(), 0.0);
  }
View Full Code Here

    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFCell cell = sheet.createRow(0).createCell(0);
   
    cell.setCellFormula("if(true,)");
    fe.clearAllCachedResultValues();
    CellValue cv;
    try {
      cv = fe.evaluate(cell);
    } catch (EmptyStackException e) {
      throw new AssertionFailedError("Missing args evaluation not implemented (bug 43354");
    }
    // MissingArg -> BlankEval -> zero (as formula result)
    assertEquals(0.0, cv.getNumberValue(), 0.0);
   
    // MissingArg -> BlankEval -> empty string (in concatenation)
    cell.setCellFormula("\"abc\"&if(true,)");
    fe.clearAllCachedResultValues();
    assertEquals("abc", fe.evaluate(cell).getStringValue());
View Full Code Here

          System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
        }
        System.out.println("-> " + cell.getCellFormula());
      }

      CellValue evalResult = eval.evaluate(cell);
      assertNotNull(evalResult);
    }
  }
View Full Code Here

    assertEquals("VLOOKUP(1,'DATA TABLE'!$A$8:'DATA TABLE'!$B$10,2)", cell
        .getCellFormula());

    // We might as well evaluate the formula
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv = fe.evaluate(cell);

    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(3.0, cv.getNumberValue(), 0.0);
  }
View Full Code Here

      }
    }
   
    // use POI's evaluator as an extra sanity check
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(1.0, cv.getNumberValue(), 0.0);
   
    cv = fe.evaluate(row.getCell(1));
    assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cv.getCellType());
    assertEquals(true, cv.getBooleanValue());
  }
View Full Code Here

    addCell(sheet1, 68, 1, 10.0); // B69

    double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0;

    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv = fe.evaluate(cell);

    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(expectedResult, 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

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.