Search in sources :

Example 26 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_NumericCoerceToString.

@Test
public void testIFEqualsFormulaEvaluation_NumericCoerceToString() {
    final String formula = "IF(A1&\"\"=\"1\", B1, C1)";
    final CellType cellType = CellType.NUMERIC;
    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 27 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_Numeric.

@Test
public void testIFEqualsFormulaEvaluation_Numeric() {
    final String formula = "IF(A1=1, B1, C1)";
    final CellType cellType = CellType.NUMERIC;
    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 28 with CellType

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

the class TestWorkbookEvaluator method testIFEqualsFormulaEvaluation_BlankInvertedSimple.

@Ignore("Bug 58591: this test currently fails")
@Test
public void testIFEqualsFormulaEvaluation_BlankInvertedSimple() {
    final String formula = "3-(NOT(A1)=1)";
    final CellType cellType = CellType.BLANK;
    final String expectedFormula = "3-(NOT(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 29 with CellType

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

the class XSSFCell method getCellFormula.

/**
     * package/hierarchy use only - reuse an existing evaluation workbook if available for caching
     *
     * @param fpb evaluation workbook for reuse, if available, or null to create a new one as needed
     * @return a formula for the cell
     * @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is not {@link CellType#FORMULA}
     */
protected String getCellFormula(XSSFEvaluationWorkbook fpb) {
    CellType cellType = getCellTypeEnum();
    if (cellType != CellType.FORMULA) {
        throw typeMismatch(CellType.FORMULA, cellType, false);
    }
    CTCellFormula f = _cell.getF();
    if (isPartOfArrayFormulaGroup() && f == null) {
        XSSFCell cell = getSheet().getFirstCellInArrayFormula(this);
        return cell.getCellFormula(fpb);
    }
    if (f.getT() == STCellFormulaType.SHARED) {
        return convertSharedFormula((int) f.getSi(), fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook()) : fpb);
    }
    return f.getStringValue();
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) STCellType(org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType) CTCellFormula(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula)

Example 30 with CellType

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

the class SXSSFCell method getDateCellValue.

/**
     * Get the value of the cell as a date.
     * <p>
     * For strings we throw an exception. For blank cells we return a null.
     * </p>
     * @return the value of the cell as a date
     * @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} is CellType.STRING
     * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
     * @see org.apache.poi.ss.usermodel.DataFormatter for formatting  this date into a string similar to how excel does.
     */
@Override
public Date getDateCellValue() {
    CellType cellType = getCellTypeEnum();
    if (cellType == CellType.BLANK) {
        return null;
    }
    double value = getNumericCellValue();
    boolean date1904 = getSheet().getWorkbook().isDate1904();
    return DateUtil.getJavaDate(value, date1904);
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType)

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