Examples of CellValue


Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

        String actualFormula=cell.getCellFormula();
        assertEquals("myFunc()", actualFormula);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
    fe.setCurrentRow(row);
    CellValue evalResult = fe.evaluate(cell);
   
    // Check the return value from ExternalFunction.evaluate()
    // TODO - make this test assert something more interesting as soon as ExternalFunction works a bit better
    assertEquals(HSSFCell.CELL_TYPE_ERROR, evalResult.getCellType());
    assertEquals(ErrorEval.FUNCTION_NOT_IMPLEMENTED.getErrorCode(), evalResult.getErrorValue());
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

    // However the range A1:B4 also includes the current cell A4.  If the other parameters
    // were 4 and 1, this would represent a circular reference.  Since POI 'fully' evaluates
    // arguments before invoking operators, POI must handle such potential cycles gracefully.
   

    CellValue cellValue = evaluateWithCycles(wb, sheet, row4, testCell);
   
    assertTrue(cellValue.getCellType() == HSSFCell.CELL_TYPE_NUMERIC);
    assertEquals(2, cellValue.getNumberValue(), 0);
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

    HSSFCell testCell = row.createCell((short)0);
    testCell.setCellFormula("A1");

    HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
    evaluator.setCurrentRow(row);
    CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

    HSSFCell testCell = row.createCell((short)3);
    testCell.setCellFormula("A1");

    HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
    evaluator.setCurrentRow(row);
    CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

    cell.setCellFormula("B1%");
    row.createCell((short)1).setCellValue(50.0);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
    fe.setCurrentRow(row);
    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

      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

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

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

    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

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

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