Search in sources :

Example 11 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_Blank.

@Test
public void testIFEqualsFormulaEvaluation_Blank() {
    final String formula = "IF(A1=1, B1, C1)";
    final CellType cellType = CellType.BLANK;
    final String expectedFormula = "IF(A1=1,B1,C1)";
    final double expectedValue = 3.0;
    testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) Test(org.junit.Test)

Example 12 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_BooleanSimple.

@Ignore("Bug 58591: this test currently fails")
@Test
public void testIFEqualsFormulaEvaluation_BooleanSimple() {
    final String formula = "3-(A1=1)";
    final CellType cellType = CellType.BOOLEAN;
    final String expectedFormula = "3-(A1=1)";
    final double expectedValue = 2.0;
    testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_Formula.

@Test
public void testIFEqualsFormulaEvaluation_Formula() {
    final String formula = "IF(A1=1, B1, C1)";
    final CellType cellType = CellType.FORMULA;
    final String expectedFormula = "IF(A1=1,B1,C1)";
    final double expectedValue = 2.0;
    testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) Test(org.junit.Test)

Example 14 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_evaluateFormulaCell.

private void testIFEqualsFormulaEvaluation_evaluateFormulaCell(String formula, CellType cellType, String expectedFormula, double expectedResult) {
    Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType);
    Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3);
    FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
    CellType resultCellType = eval.evaluateFormulaCellEnum(D1);
    // Call should modify the contents, but leave the formula intact
    assertEquals(CellType.FORMULA, D1.getCellTypeEnum());
    assertEquals(expectedFormula, D1.getCellFormula());
    assertEquals(CellType.NUMERIC, resultCellType);
    assertEquals(CellType.NUMERIC, D1.getCachedFormulaResultTypeEnum());
    assertEquals(expectedResult, D1.getNumericCellValue(), EPSILON);
    testIFEqualsFormulaEvaluation_teardown(wb);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 15 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_StringCompareToString.

@Test
public void testIFEqualsFormulaEvaluation_StringCompareToString() {
    final String formula = "IF(A1=\"1\", B1, C1)";
    final CellType cellType = CellType.STRING;
    final String expectedFormula = "IF(A1=\"1\",B1,C1)";
    final double expectedValue = 2.0;
    testIFEqualsFormulaEvaluation_eval(formula, cellType, expectedFormula, expectedValue);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) Test(org.junit.Test)

Aggregations

CellType (org.apache.poi.ss.usermodel.CellType)32 Test (org.junit.Test)17 STCellType (org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType)7 RichTextString (org.apache.poi.ss.usermodel.RichTextString)5 Cell (org.apache.poi.ss.usermodel.Cell)4 CellValue (org.apache.poi.ss.usermodel.CellValue)4 Row (org.apache.poi.ss.usermodel.Row)4 Ignore (org.junit.Ignore)4 CellStyle (org.apache.poi.ss.usermodel.CellStyle)3 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)2 CTCellFormula (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula)2 AttributedString (java.text.AttributedString)1 AssertionFailedError (junit.framework.AssertionFailedError)1 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 CellReference (org.apache.poi.hssf.util.CellReference)1 Font (org.apache.poi.ss.usermodel.Font)1