use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula in project poi by apache.
the class TestXSSFSheetUpdateArrayFormulas method confirmArrayFormulaCell.
private static void confirmArrayFormulaCell(XSSFCell c, String cellRef, String formulaText, String arrayRangeRef) {
if (c == null) {
throw new AssertionFailedError("Cell should not be null.");
}
CTCell ctCell = c.getCTCell();
assertEquals(cellRef, ctCell.getR());
if (formulaText == null) {
assertFalse(ctCell.isSetF());
assertNull(ctCell.getF());
} else {
CTCellFormula f = ctCell.getF();
assertEquals(arrayRangeRef, f.getRef());
assertEquals(formulaText, f.getStringValue());
assertEquals(STCellFormulaType.ARRAY, f.getT());
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula in project poi by apache.
the class XSSFCell method setFormula.
private void setFormula(String formula, FormulaType formulaType) {
XSSFWorkbook wb = _row.getSheet().getWorkbook();
if (formula == null) {
wb.onDeleteFormula(this);
if (_cell.isSetF()) {
_cell.unsetF();
}
return;
}
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
//validate through the FormulaParser
FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex());
CTCellFormula f = CTCellFormula.Factory.newInstance();
f.setStringValue(formula);
_cell.setF(f);
if (_cell.isSetV()) {
_cell.unsetV();
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula 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();
}
Aggregations