From abdf3c9c46982d67045eced1b009bbcaa152b692 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Mon, 2 Feb 2009 23:10:30 +0000 Subject: [PATCH] Fix for bug 46643 - formula parser should encode range operator with tMemFunc git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740146 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/ss/formula/FormulaParser.java | 8 ++++++- .../poi/hssf/model/TestFormulaParser.java | 23 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index e8b0f419c4..eb6c43861a 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 46643 - Fixed formula parser to encode range operator with tMemFunc 46647 - Fixed COUNTIF NE operator and other special cases involving type conversion 46635 - Added a method to remove slides 46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index c96bd23f6a..45ebb7b03a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46643 - Fixed formula parser to encode range operator with tMemFunc 46647 - Fixed COUNTIF NE operator and other special cases involving type conversion 46635 - Added a method to remove slides 46520 - Fixed HSSFFont.applyFont() to properly apply font to overlapping regions diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java index 1a3edcdd59..c05ef4475c 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java @@ -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; diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index b951ae3b62..a6ff9fd519 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -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()); + } } -- 2.39.5