View | Details | Raw Unified | Return to bug 57840
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (-4 / +15 lines)
Lines 469-484 Link Here
469
     */
469
     */
470
    @Override
470
    @Override
471
    public String getCellFormula() {
471
    public String getCellFormula() {
472
        // existing behavior - create a new XSSFEvaluationWorkbook for every call
473
        return getCellFormula(null);
474
    }
475
    
476
    /**
477
     * package/hierarchy use only - reuse an existing evaluation workbook if available for caching
478
     *
479
     * @param fpb evaluation workbook for reuse, if available, or null to create a new one as needed
480
     * @return a formula for the cell
481
     * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not CELL_TYPE_FORMULA
482
     */
483
    protected String getCellFormula(XSSFEvaluationWorkbook fpb) {
472
        int cellType = getCellType();
484
        int cellType = getCellType();
473
        if(cellType != CELL_TYPE_FORMULA) throw typeMismatch(CELL_TYPE_FORMULA, cellType, false);
485
        if(cellType != CELL_TYPE_FORMULA) throw typeMismatch(CELL_TYPE_FORMULA, cellType, false);
474
486
475
        CTCellFormula f = _cell.getF();
487
        CTCellFormula f = _cell.getF();
476
        if (isPartOfArrayFormulaGroup() && f == null) {
488
        if (isPartOfArrayFormulaGroup() && f == null) {
477
            XSSFCell cell = getSheet().getFirstCellInArrayFormula(this);
489
            XSSFCell cell = getSheet().getFirstCellInArrayFormula(this);
478
            return cell.getCellFormula();
490
            return cell.getCellFormula(fpb);
479
        }
491
        }
480
        if (f.getT() == STCellFormulaType.SHARED) {
492
        if (f.getT() == STCellFormulaType.SHARED) {
481
            return convertSharedFormula((int)f.getSi());
493
            return convertSharedFormula((int)f.getSi(), fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook()) : fpb);
482
        }
494
        }
483
        return f.getStringValue();
495
        return f.getStringValue();
484
    }
496
    }
Lines 489-495 Link Here
489
     * @param si Shared Group Index
501
     * @param si Shared Group Index
490
     * @return non shared formula created for the given shared formula and this cell
502
     * @return non shared formula created for the given shared formula and this cell
491
     */
503
     */
492
    private String convertSharedFormula(int si){
504
    private String convertSharedFormula(int si, XSSFEvaluationWorkbook fpb){
493
        XSSFSheet sheet = getSheet();
505
        XSSFSheet sheet = getSheet();
494
506
495
        CTCellFormula f = sheet.getSharedFormula(si);
507
        CTCellFormula f = sheet.getSharedFormula(si);
Lines 503-509 Link Here
503
        CellRangeAddress ref = CellRangeAddress.valueOf(sharedFormulaRange);
515
        CellRangeAddress ref = CellRangeAddress.valueOf(sharedFormulaRange);
504
516
505
        int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
517
        int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
506
        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(sheet.getWorkbook());
507
        SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL2007);
518
        SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL2007);
508
519
509
        Ptg[] ptgs = FormulaParser.parse(sharedFormula, fpb, FormulaType.CELL, sheetIndex, getRowIndex());
520
        Ptg[] ptgs = FormulaParser.parse(sharedFormula, fpb, FormulaType.CELL, sheetIndex, getRowIndex());
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (-1 / +1 lines)
Lines 52-57 Link Here
52
    @Override    
52
    @Override    
53
    public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
53
    public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
54
        XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
54
        XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
55
        return FormulaParser.parse(cell.getCellFormula(), this, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()), cell.getRowIndex());
55
        return FormulaParser.parse(cell.getCellFormula(this), this, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()), cell.getRowIndex());
56
    }
56
    }
57
}
57
}

Return to bug 57840