Search in sources :

Example 31 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.

the class TestIndirect method confirm.

private static void confirm(FormulaEvaluator fe, Cell cell, String formula, double expectedResult) {
    fe.clearAllCachedResultValues();
    cell.setCellFormula(formula);
    CellValue cv = fe.evaluate(cell);
    if (cv.getCellTypeEnum() != CellType.NUMERIC) {
        fail("expected numeric cell type but got " + cv.formatAsString());
    }
    assertEquals(expectedResult, cv.getNumberValue(), 0.0);
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue)

Example 32 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.

the class TestIndirect method confirm.

private static void confirm(FormulaEvaluator fe, Cell cell, String formula, ErrorEval expectedResult) {
    fe.clearAllCachedResultValues();
    cell.setCellFormula(formula);
    CellValue cv = fe.evaluate(cell);
    if (cv.getCellTypeEnum() != CellType.ERROR) {
        fail("expected error cell type but got " + cv.formatAsString());
    }
    int expCode = expectedResult.getErrorCode();
    if (cv.getErrorValue() != expCode) {
        fail("Expected error '" + ErrorEval.getText(expCode) + "' but got '" + cv.formatAsString() + "'.");
    }
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue)

Example 33 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.

the class TestFind method confirmError.

private static void confirmError(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText, FormulaError expectedErrorCode) {
    cell.setCellFormula(formulaText);
    fe.notifyUpdateCell(cell);
    CellValue result = fe.evaluate(cell);
    assertEquals(result.getCellTypeEnum(), CellType.ERROR);
    assertEquals(expectedErrorCode.getCode(), result.getErrorValue());
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue)

Example 34 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.

the class TestFixed method confirmValueError.

private void confirmValueError(String formulaText) {
    cell11.setCellFormula(formulaText);
    evaluator.clearAllCachedResultValues();
    CellValue cv = evaluator.evaluate(cell11);
    assertTrue("Wrong result type: " + cv.formatAsString(), cv.getCellTypeEnum() == CellType.ERROR && cv.getErrorValue() == FormulaError.VALUE.getCode());
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue)

Example 35 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.

the class TestIsBlank method test3DArea.

public void test3DArea() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet1 = wb.createSheet();
    wb.setSheetName(0, "Sheet1");
    wb.createSheet();
    wb.setSheetName(1, "Sheet2");
    HSSFRow row = sheet1.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("isblank(Sheet2!A1:A1)");
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue result = fe.evaluate(cell);
    assertEquals(CellType.BOOLEAN, result.getCellTypeEnum());
    assertEquals(true, result.getBooleanValue());
    cell.setCellFormula("isblank(D7:D7)");
    result = fe.evaluate(cell);
    assertEquals(CellType.BOOLEAN, result.getCellTypeEnum());
    assertEquals(true, result.getBooleanValue());
}
Also used : HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellValue(org.apache.poi.ss.usermodel.CellValue) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

CellValue (org.apache.poi.ss.usermodel.CellValue)63 Test (org.junit.Test)24 Cell (org.apache.poi.ss.usermodel.Cell)18 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)15 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 AssertionFailedError (junit.framework.AssertionFailedError)12 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)11 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)10 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)10 Row (org.apache.poi.ss.usermodel.Row)10 Workbook (org.apache.poi.ss.usermodel.Workbook)8 Sheet (org.apache.poi.ss.usermodel.Sheet)7 CellType (org.apache.poi.ss.usermodel.CellType)4 CellReference (org.apache.poi.ss.util.CellReference)4 CellReference (org.apache.poi.hssf.util.CellReference)2 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)2 FreeRefFunction (org.apache.poi.ss.formula.functions.FreeRefFunction)2 File (java.io.File)1 EmptyStackException (java.util.EmptyStackException)1