public CellRangeAddress getArrayFormulaRange() { XSSFCell cell = getSheet().getFirstCellInArrayFormula(this); if (cell == null) { throw new IllegalStateException("Cell " + _cell.getR() + " is not part of an array formula."); } String formulaRef = cell._cell.getF().getRef(); return CellRangeAddress.valueOf(formulaRef); }
/** * Creates a non shared formula from the shared formula counterpart * * @param si Shared Group Index * @return non shared formula created for the given shared formula and this cell */ private String convertSharedFormula(int si) { XSSFSheet sheet = getSheet(); CTCellFormula f = sheet.getSharedFormula(si); if (f == null) throw new IllegalStateException( "Master cell of a shared formula with sid=" + si + " was not found"); String sharedFormula = f.getStringValue(); // Range of cells which the shared formula applies to String sharedFormulaRange = f.getRef(); CellRangeAddress ref = CellRangeAddress.valueOf(sharedFormulaRange); int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet); XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(sheet.getWorkbook()); SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL2007); Ptg[] ptgs = FormulaParser.parse(sharedFormula, fpb, FormulaType.CELL, sheetIndex); Ptg[] fmla = sf.convertSharedFormulas( ptgs, getRowIndex() - ref.getFirstRow(), getColumnIndex() - ref.getFirstColumn()); return FormulaRenderer.toFormulaString(fpb, fmla); }