You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by gw...@apache.org on 2019/03/30 18:14:14 UTC

svn commit: r1856644 - in /poi/trunk: src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java test-data/spreadsheet/external_name.xls

Author: gwoolsey
Date: Sat Mar 30 18:14:14 2019
New Revision: 1856644

URL: http://svn.apache.org/viewvc?rev=1856644&view=rev
Log:
#63302 Formula evaluation of names with offset or row function is incorrect

thanks to John Lincoln White for the patch, including new unit tests.

Added:
    poi/trunk/test-data/spreadsheet/external_name.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=1856644&r1=1856643&r2=1856644&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Sat Mar 30 18:14:14 2019
@@ -773,10 +773,12 @@ public final class WorkbookEvaluator {
      * YK: Used by OperationEvaluationContext to resolve indirect names.
      */
     /*package*/ ValueEval evaluateNameFormula(Ptg[] ptgs, OperationEvaluationContext ec) {
-    if (ptgs.length == 1) {
-      return getEvalForPtg(ptgs[0], ec);
-    }
-      return evaluateFormula(ec, ptgs);
+      if (ptgs.length == 1 && !(ptgs[0] instanceof FuncVarPtg)) {
+        return getEvalForPtg(ptgs[0], ec);
+      }
+        
+      OperationEvaluationContext anyValueContext = new OperationEvaluationContext(this, ec.getWorkbook(), ec.getSheetIndex(), ec.getRowIndex(), ec.getColumnIndex(), new EvaluationTracker(_cache), false);
+      return evaluateFormula(anyValueContext, ptgs);
     }
 
     /**

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java?rev=1856644&r1=1856643&r2=1856644&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestWorkbookEvaluator.java Sat Mar 30 18:14:14 2019
@@ -274,12 +274,22 @@ public class TestWorkbookEvaluator {
         Name name3 = wb.createName();
         name3.setNameName("aSet");
         name3.setRefersToFormula("Sheet1!$A$2:$A$4");
-
+        
+        Name name4 = wb.createName();
+        name4.setNameName("offsetFormula");
+        name4.setRefersToFormula("OFFSET(Sheet1!$A$1:$A$4,2,0,2,1)");
+        
+        Name name5 = wb.createName();
+        name5.setNameName("rowFormula");
+        name5.setRefersToFormula("ROW()");
         
         Row row0 = sheet.createRow(0);
         Row row1 = sheet.createRow(1);
         Row row2 = sheet.createRow(2);
         Row row3 = sheet.createRow(3);
+        Row row4 = sheet.createRow(4);
+        Row row5 = sheet.createRow(5);
+        
         row0.createCell(0).setCellValue(2);
         row1.createCell(0).setCellValue(5);
         row2.createCell(0).setCellValue(3);
@@ -289,16 +299,20 @@ public class TestWorkbookEvaluator {
         row1.createCell(2).setCellFormula("aFormula");
         row2.createCell(2).setCellFormula("SUM(aSet)");
         row3.createCell(2).setCellFormula("aConstant+aFormula+SUM(aSet)");
+        row4.createCell(2).setCellFormula("SUM(offsetFormula)");
+        row5.createCell(2).setCellFormula("rowFormula");
 
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
         assertEquals(3.14, fe.evaluate(row0.getCell(2)).getNumberValue(), EPSILON);
         assertEquals(10.0, fe.evaluate(row1.getCell(2)).getNumberValue(), EPSILON);
         assertEquals(15.0, fe.evaluate(row2.getCell(2)).getNumberValue(), EPSILON);
         assertEquals(28.14, fe.evaluate(row3.getCell(2)).getNumberValue(), EPSILON);
+        assertEquals(10.0, fe.evaluate(row4.getCell(2)).getNumberValue(), EPSILON);
+        assertEquals(6.0, fe.evaluate(row5.getCell(2)).getNumberValue(), EPSILON);
         
         wb.close();
     }
-
+    
     @Test
     public void testIgnoreMissingWorkbooks() {
         // TODO: update this test for meaningful functional behavior

Added: poi/trunk/test-data/spreadsheet/external_name.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/external_name.xls?rev=1856644&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/external_name.xls
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-excel



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