Search in sources :

Example 61 with CellValue

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

the class TestDate method confirm.

private void confirm(String formulaText, double expectedResult) {
    cell11.setCellFormula(formulaText);
    evaluator.clearAllCachedResultValues();
    CellValue cv = evaluator.evaluate(cell11);
    if (cv.getCellTypeEnum() != CellType.NUMERIC) {
        throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
    }
    double actualValue = cv.getNumberValue();
    assertEquals(expectedResult, actualValue, 0);
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError)

Example 62 with CellValue

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

the class TestCalendarFieldFunction method confirm.

private void confirm(String formulaText, double expectedResult) {
    cell11.setCellFormula(formulaText);
    evaluator.clearAllCachedResultValues();
    CellValue cv = evaluator.evaluate(cell11);
    if (cv.getCellTypeEnum() != CellType.NUMERIC) {
        throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
    }
    double actualValue = cv.getNumberValue();
    assertEquals(expectedResult, actualValue, 0);
}
Also used : CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError)

Example 63 with CellValue

use of org.apache.poi.ss.usermodel.CellValue in project chilo-producer by cccties.

the class ExcelReader method getStringFormulaValue.

public String getStringFormulaValue(Cell cell) {
    assert cell.getCellType() == Cell.CELL_TYPE_FORMULA;
    CreationHelper helper = workBook.getCreationHelper();
    FormulaEvaluator evaluator = helper.createFormulaEvaluator();
    CellValue value = evaluator.evaluate(cell);
    switch(value.getCellType()) {
        case Cell.CELL_TYPE_STRING:
            return value.getStringValue();
        case Cell.CELL_TYPE_NUMERIC:
            return Double.toString(value.getNumberValue());
        case Cell.CELL_TYPE_BOOLEAN:
            return Boolean.toString(value.getBooleanValue());
        default:
            System.out.println(value.getCellType());
            return null;
    }
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) CellValue(org.apache.poi.ss.usermodel.CellValue) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

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