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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations