]> source.dussan.org Git - poi.git/commitdiff
Fix for bug 46643 - formula parser should encode range operator with tMemFunc
authorJosh Micich <josh@apache.org>
Mon, 2 Feb 2009 23:10:30 +0000 (23:10 +0000)
committerJosh Micich <josh@apache.org>
Mon, 2 Feb 2009 23:10:30 +0000 (23:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740146 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/formula/FormulaParser.java
src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java

index e8b0f419c44d174460ff13851f43e4d1b9f49c22..eb6c43861a572ea66021191f4703f1c5e42cc1c8 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
            <action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
            <action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
            <action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
index c96bd23f6ad68989c5865fa6e68d8cf54c4e8398..45ebb7b03a71a064bbf7d982f73412094e1e6611 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
            <action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
            <action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
            <action dev="POI-DEVELOPERS" type="fix">46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions</action>
index 1a3edcdd5972053d33215a984617a593dc224976..c05ef4475cca6961dffbe446802260a29ee93325 100644 (file)
@@ -344,7 +344,9 @@ public final class FormulaParser {
                     new ParseNode(ptgA),    
                     new ParseNode(ptgB),
                 };
-                return new ParseNode(RangePtg.instance, children);
+                ParseNode result = new ParseNode(RangePtg.instance, children);
+                MemFuncPtg memFuncPtg = new MemFuncPtg(result.getEncodedSize());
+                return new ParseNode(memFuncPtg, result);
             }
             return new ParseNode(simplified);
         }
@@ -590,6 +592,10 @@ public final class FormulaParser {
         }
         boolean isVarArgs = !fm.hasFixedArgsLength();
         int funcIx = fm.getIndex();
+        if (false && funcIx == 4 && args.length == 1) {
+            // TODO - make POI behave more like Excel when summing a single argument:
+            // return new ParseNode(AttrPtg.getSumSingle(), args);
+        }
         validateNumArgs(args.length, fm);
 
         AbstractFunctionPtg retval;
index b951ae3b621761f35e4f8ca10e50c44875a7422c..a6ff9fd5192c99818f202bc56fca82e15f7b16bf 100644 (file)
@@ -45,6 +45,7 @@ import org.apache.poi.hssf.record.formula.NumberPtg;
 import org.apache.poi.hssf.record.formula.PercentPtg;
 import org.apache.poi.hssf.record.formula.PowerPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.RangePtg;
 import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.hssf.record.formula.StringPtg;
@@ -973,4 +974,26 @@ public final class TestFormulaParser extends TestCase {
                MemFuncPtg mf = (MemFuncPtg)ptgs[0];
                assertEquals(45, mf.getLenRefSubexpression());
        }
+
+       public void testRange_bug46643() {
+               String formula = "Sheet1!A1:Sheet1!B3";
+               HSSFWorkbook wb = new HSSFWorkbook();
+               wb.createSheet("Sheet1");
+               Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb));
+
+               if (ptgs.length == 3) {
+                       confirmTokenClasses(ptgs, new Class[] { Ref3DPtg.class, Ref3DPtg.class, RangePtg.class,});
+                       throw new AssertionFailedError("Identified bug 46643");
+               }
+               
+               Class [] expectedClasses = {
+                               MemFuncPtg.class,
+                               Ref3DPtg.class,
+                               Ref3DPtg.class,
+                               RangePtg.class,
+               };
+               confirmTokenClasses(ptgs, expectedClasses);
+               MemFuncPtg mf = (MemFuncPtg)ptgs[0];
+               assertEquals(15, mf.getLenRefSubexpression());
+       }
 }