Package org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator

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


        
        cell.setCellFormula("isblank(Sheet2!A1:A1)");
       
        HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
        fe.setCurrentRow(row);
        CellValue result = fe.evaluate(cell);
        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
        assertEquals(true, result.getBooleanValue());
       
        cell.setCellFormula("isblank(D7:D7)");
       
        result = fe.evaluate(cell);
        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
        assertEquals(true, result.getBooleanValue());
       
   }
View Full Code Here

      HSSFCell c = r.getCell(SS.COLUMN_INDEX_EVALUATION);
      if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
        continue;
      }
      evaluator.setCurrentRow(r);
      CellValue actualValue = evaluator.evaluate(c);
      HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
      String rowComment = getRowCommentColumnValue(r);
     
      String msgPrefix = formatTestCaseDetails(sheetName, r.getRowNum(), c, currentGroupComment, rowComment);
      try {
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

        .getCellFormula());

    // We might as well evaluate the formula
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
    fe.setCurrentRow(row);
    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(sheet, wb);
    fe.setCurrentRow(row);
    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

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

    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
    fe.setCurrentRow(row);
    CellValue cv = fe.evaluate(cell);

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

        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

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

    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

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.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.