use of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate in project poi by apache.
the class HSSFCell method setCellArrayFormula.
void setCellArrayFormula(CellRangeAddress range) {
int row = _record.getRow();
short col = _record.getColumn();
short styleIndex = _record.getXFIndex();
setCellType(CellType.FORMULA, false, row, col, styleIndex);
// Billet for formula in rec
Ptg[] ptgsForCell = { new ExpPtg(range.getFirstRow(), range.getFirstColumn()) };
FormulaRecordAggregate agg = (FormulaRecordAggregate) _record;
agg.setParsedExpression(ptgsForCell);
}
use of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate in project poi by apache.
the class TestHSSFSheetUpdateArrayFormulas method testHSSFSetArrayFormula_singleCell.
// Test methods common with XSSF are in superclass
// Local methods here test HSSF-specific details of updating array formulas
@Test
public void testHSSFSetArrayFormula_singleCell() throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2);
HSSFCell[] cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells();
assertEquals(1, cells.length);
// sheet.setArrayFormula creates rows and cells for the designated range
assertNotNull(sheet.getRow(2));
HSSFCell cell = sheet.getRow(2).getCell(2);
assertNotNull(cell);
assertTrue(cell.isPartOfArrayFormulaGroup());
//retrieve the range and check it is the same
assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString());
FormulaRecordAggregate agg = (FormulaRecordAggregate) cell.getCellValueRecord();
assertEquals(range.formatAsString(), agg.getArrayFormulaRange().formatAsString());
assertTrue(agg.isPartOfArrayFormula());
workbook.close();
}
use of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate in project poi by apache.
the class HSSFCell method getNumericCellValue.
/**
* Get the value of the cell as a number.
* For strings we throw an exception.
* For blank cells we return a 0.
* See {@link HSSFDataFormatter} for turning this
* number into a string similar to that which
* Excel would render this number as.
*/
public double getNumericCellValue() {
switch(_cellType) {
case BLANK:
return 0.0;
case NUMERIC:
return ((NumberRecord) _record).getValue();
default:
throw typeMismatch(CellType.NUMERIC, _cellType, false);
case FORMULA:
break;
}
FormulaRecord fr = ((FormulaRecordAggregate) _record).getFormulaRecord();
checkFormulaCachedValueType(CellType.NUMERIC, fr);
return fr.getValue();
}
use of org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate in project poi by apache.
the class HSSFCell method convertCellValueToBoolean.
/**
* Chooses a new boolean value for the cell when its type is changing.<p/>
*
* Usually the caller is calling setCellType() with the intention of calling
* setCellValue(boolean) straight afterwards. This method only exists to give
* the cell a somewhat reasonable value until the setCellValue() call (if at all).
* TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
*/
private boolean convertCellValueToBoolean() {
switch(_cellType) {
case BOOLEAN:
return ((BoolErrRecord) _record).getBooleanValue();
case STRING:
int sstIndex = ((LabelSSTRecord) _record).getSSTIndex();
String text = _book.getWorkbook().getSSTString(sstIndex).getString();
return Boolean.valueOf(text).booleanValue();
case NUMERIC:
return ((NumberRecord) _record).getValue() != 0;
case FORMULA:
// use cached formula result if it's the right type:
FormulaRecord fr = ((FormulaRecordAggregate) _record).getFormulaRecord();
checkFormulaCachedValueType(CellType.BOOLEAN, fr);
return fr.getCachedBooleanValue();
// These choices are not well justified.
case ERROR:
case BLANK:
return false;
}
throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
}
Aggregations