Examples of CellValue


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

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

    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

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

        }

    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

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

       for(int i=0; i<wb.getNumberOfSheets(); i++) {
          Sheet s = wb.getSheetAt(i);
          for(Row r : s) {
             for(Cell c : r) {
                if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
                    CellValue cv = eval.evaluate(c);
                    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

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

    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("1+IF(1,,)");
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
      cv = fe.evaluate(cell);
    } catch (RuntimeException e) {
      throw new AssertionFailedError("Missing arg result not being handled correctly.");
    }
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    // adding blank to 1.0 gives 1.0
    assertEquals(1.0, cv.getNumberValue(), 0.0);

    // check with string operand
    cell.setCellFormula("\"abc\"&IF(1,,)");
    fe.notifySetFormula(cell);
    cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
    // adding blank to "abc" gives "abc"
    assertEquals("abc", cv.getStringValue());
   
    // check CHOOSE()
    cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)");
    fe.notifySetFormula(cell);
    cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
    // adding blank to "abc" gives "abc"
    assertEquals("abc", cv.getStringValue());
  }
View Full Code Here

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

  private Object getCellValue(Cell cell, FormulaEvaluator evaluator)
   throws ExcelManipulateException
    if(cell == null) return null;
    //log.debug("Read Value for: " + ExcelUtil.getCellIndex(cell.getRowIndex(), cell.getColumnIndex()));
    Object value = null;
    CellValue cellValue = evaluator.evaluate(cell);
    if(cellValue == null) {
      logger.debug("{}: null",ExcelUtil.getCellIndex(cell.getRowIndex(), cell.getColumnIndex()));
      return null;
    }
    switch(cellValue.getCellType()){
    case Cell.CELL_TYPE_BLANK:
    case Cell.CELL_TYPE_ERROR:     
      break;     
    case Cell.CELL_TYPE_BOOLEAN:
      value = cellValue.getBooleanValue();
      break;
    case Cell.CELL_TYPE_NUMERIC:
      if(DateUtil.isCellDateFormatted(cell)) {
        value = DateUtil.getJavaDate(cellValue.getNumberValue());
      }else
        value = cellValue.getNumberValue();
      break;
    case Cell.CELL_TYPE_STRING:
      value = cellValue.getStringValue();
    }
    logger.debug("{}: {}", ExcelUtil.getCellIndex(cell.getRowIndex(), cell.getColumnIndex()), value);
    return value;
  }
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

      HSSFRow row = sheet.getRow(rowIx);
      if(row == null) {
        continue;
      }
      HSSFCell cell = row.getCell(COL_IX_ACTUAL);
      CellValue cv = fe.evaluate(cell);
      double actualValue = cv.getNumberValue();
      double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue();
      if (actualValue != expectedValue) {
        System.err.println("Problem with test case on row " + (rowIx+1) + " "
            + "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ");
        failureCount++;
View Full Code Here

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


    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
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.