Examples of CellValue


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

    cellC1.setCellFormula("1+D1");
    cellD1.setCellFormula("1+E1");
    cellE1.setCellFormula("1+A1");
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
   
    // Happy day flow - evaluate A1 first
    cv = fe.evaluate(cellA1);
    assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(42.0, cv.getNumberValue(), 0.0);
    cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached
    assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(46.0, cv.getNumberValue(), 0.0);
   
    // Show the bug - evaluate another cell from the loop first
    fe.clearAllCachedResultValues();
    cv = fe.evaluate(cellB1);
    if (cv.getCellType() == ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()) {
      throw new AssertionFailedError("Identified bug 46898");
    }
    assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(46.0, cv.getNumberValue(), 0.0);

    // start evaluation on another cell
    fe.clearAllCachedResultValues();
    cv = fe.evaluate(cellE1);
    assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(43.0, cv.getNumberValue(), 0.0);
   
   
  }
View Full Code Here

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

    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("B1%");
    row.createCell(1).setCellValue(50.0);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
      cv = fe.evaluate(cell);
    } catch (RuntimeException e) {
      if(e.getCause() instanceof NullPointerException) {
        throw new AssertionFailedError("Identified bug 44608");
      }
      // else some other unexpected error
      throw e;
    }
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(0.5, cv.getNumberValue(), 0.0);
  }
View Full Code Here

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

    String actualFormula=cell.getCellFormula();
    assertEquals("myFunc()", actualFormula);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    // Check out what ExternalFunction.evaluate() does:
    CellValue evalResult;
    try {
      evalResult = fe.evaluate(cell);
    } catch (NotImplementedException e) {
      assertEquals("Error evaluating cell Sheet1!B1", e.getMessage());
      assertEquals("myFunc", e.getCause().getMessage());
View Full Code Here

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

    cellA1.setCellFormula("SUM(C1:OFFSET(C1,0,B1))");

    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

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

    Cell c = formulasRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE);
    if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
      return result;
    }

    CellValue actualValue = evaluator.evaluate(c);

    try {
      confirmExpectedResult("Function '" + targetFunctionName + "': Test: '" + targetTestName + "' Formula: " + c.getCellFormula()
      + " @ " + formulasRow.getRowNum() + ":" + SS.COLUMN_INDEX_ACTUAL_VALUE,
          expectedValueCell, actualValue);
View Full Code Here

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

  private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
      HSSFFormulaEvaluator fe, String expectedFormula, double expectedResult) {
    HSSFCell cell = sheet.getRow(rowIx).getCell(colIx);
    assertEquals(expectedFormula, cell.getCellFormula());
    CellValue cv = fe.evaluate(cell);
    assertEquals(expectedResult, cv.getNumberValue(), 0.0);
  }
View Full Code Here

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

  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

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

    // Set the complex flag - POI doesn't usually manipulate this flag
    NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
    nameRec.setOptionFlag((short)0x10); // 0x10 -> complex

    HSSFFormulaEvaluator hsf = new HSSFFormulaEvaluator(wb);
    CellValue value;
    try {
      value = hsf.evaluate(cellA1);
    } catch (RuntimeException e) {
      if (e.getMessage().equals("Don't now how to evalate name 'Is_Multicar_Vehicle'")) {
        throw new AssertionFailedError("Identified bug 47048a");
      }
      throw e;
    }

    assertEquals(Cell.CELL_TYPE_NUMERIC, value.getCellType());
    assertEquals(5.33, value.getNumberValue(), 0.0);
  }
View Full Code Here

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

      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

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

   */
  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
TOP
Copyright © 2018 www.massapi.com. 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.