poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1747840 - in /poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel: XSSFCell.java XSSFEvaluationWorkbook.java
Date Sat, 11 Jun 2016 02:28:22 GMT
Author: onealj
Date: Sat Jun 11 02:28:21 2016
New Revision: 1747840

URL: http://svn.apache.org/viewvc?rev=1747840&view=rev
Log:
bug 57840: re-use XSSFEvaluationWorkbook when expanding a shared formula; patch from Greg
Woolsey

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1747840&r1=1747839&r2=1747840&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sat Jun 11 02:28:21
2016
@@ -469,16 +469,28 @@ public final class XSSFCell implements C
      */
     @Override
     public String getCellFormula() {
+        // existing behavior - create a new XSSFEvaluationWorkbook for every call
+        return getCellFormula(null);
+    }
+    
+    /**
+     * 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 #getCellType()}
is not CELL_TYPE_FORMULA
+     */
+    protected String getCellFormula(XSSFEvaluationWorkbook fpb) {
         int cellType = getCellType();
         if(cellType != CELL_TYPE_FORMULA) throw typeMismatch(CELL_TYPE_FORMULA, cellType,
false);
 
         CTCellFormula f = _cell.getF();
         if (isPartOfArrayFormulaGroup() && f == null) {
             XSSFCell cell = getSheet().getFirstCellInArrayFormula(this);
-            return cell.getCellFormula();
+            return cell.getCellFormula(fpb);
         }
         if (f.getT() == STCellFormulaType.SHARED) {
-            return convertSharedFormula((int)f.getSi());
+            return convertSharedFormula((int)f.getSi(), fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook())
: fpb);
         }
         return f.getStringValue();
     }
@@ -489,7 +501,7 @@ public final class XSSFCell implements C
      * @param si Shared Group Index
      * @return non shared formula created for the given shared formula and this cell
      */
-    private String convertSharedFormula(int si){
+    private String convertSharedFormula(int si, XSSFEvaluationWorkbook fpb){
         XSSFSheet sheet = getSheet();
 
         CTCellFormula f = sheet.getSharedFormula(si);
@@ -503,7 +515,6 @@ public final class XSSFCell implements C
         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,
getRowIndex());

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java?rev=1747840&r1=1747839&r2=1747840&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java Sat
Jun 11 02:28:21 2016
@@ -67,7 +67,9 @@ public final class XSSFEvaluationWorkboo
 
     @Override    
     public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
-        XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
-        return FormulaParser.parse(cell.getCellFormula(), this, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()),
cell.getRowIndex());
+        final XSSFCell cell = ((XSSFEvaluationCell)evalCell).getXSSFCell();
+        final int sheetIndex = _uBook.getSheetIndex(cell.getSheet());
+        final int rowIndex = cell.getRowIndex();
+        return FormulaParser.parse(cell.getCellFormula(this), this, FormulaType.CELL, sheetIndex,
rowIndex);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message