aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/ss
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-02-02 23:53:22 +0000
committerJosh Micich <josh@apache.org>2009-02-02 23:53:22 +0000
commit7df009dfd998e34286aef2d33ca10de94dfe51ce (patch)
tree7efa361c4f593b99893f15f8cfce93c06d42631b /src/java/org/apache/poi/ss
parentabdf3c9c46982d67045eced1b009bbcaa152b692 (diff)
downloadpoi-7df009dfd998e34286aef2d33ca10de94dfe51ce.tar.gz
poi-7df009dfd998e34286aef2d33ca10de94dfe51ce.zip
Modified formula parser to encode SUM taking a single argument as tAttrSum (from comment 7 of bugzilla 46643)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740159 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/ss')
-rw-r--r--src/java/org/apache/poi/ss/formula/FormulaParser.java9
-rw-r--r--src/java/org/apache/poi/ss/formula/OperandClassTransformer.java17
2 files changed, 23 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java
index c05ef4475c..e67e6b3023 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -27,6 +27,7 @@ import org.apache.poi.hssf.record.formula.AddPtg;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.AreaPtg;
import org.apache.poi.hssf.record.formula.ArrayPtg;
+import org.apache.poi.hssf.record.formula.AttrPtg;
import org.apache.poi.hssf.record.formula.BoolPtg;
import org.apache.poi.hssf.record.formula.ConcatPtg;
import org.apache.poi.hssf.record.formula.DividePtg;
@@ -592,9 +593,11 @@ 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);
+ if (funcIx == FunctionMetadataRegistry.FUNCTION_INDEX_SUM && args.length == 1) {
+ // Excel encodes the sum of a single argument as tAttrSum
+ // POI does the same for consistency, but this is not critical
+ return new ParseNode(AttrPtg.getSumSingle(), args);
+ // The code below would encode tFuncVar(SUM) which seems to do no harm
}
validateNumArgs(args.length, fm);
diff --git a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java
index 8403400432..6a6e676a1f 100644
--- a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java
+++ b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java
@@ -18,7 +18,9 @@
package org.apache.poi.ss.formula;
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
+import org.apache.poi.hssf.record.formula.AttrPtg;
import org.apache.poi.hssf.record.formula.ControlPtg;
+import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.RangePtg;
@@ -101,6 +103,13 @@ final class OperandClassTransformer {
return;
}
+ if (isSingleArgSum(token)) {
+ // Need to process the argument of SUM with transformFunctionNode below
+ // so make a dummy FuncVarPtg for that call.
+ token = new FuncVarPtg("SUM", (byte)1);
+ // Note - the tAttrSum token (node.getToken()) is a base
+ // token so does not need to have its operand class set
+ }
if (token instanceof ValueOperatorPtg || token instanceof ControlPtg
|| token instanceof MemFuncPtg
|| token instanceof UnionPtg) {
@@ -135,6 +144,14 @@ final class OperandClassTransformer {
token.setClass(transformClass(token.getPtgClass(), desiredOperandClass, callerForceArrayFlag));
}
+ private static boolean isSingleArgSum(Ptg token) {
+ if (token instanceof AttrPtg) {
+ AttrPtg attrPtg = (AttrPtg) token;
+ return attrPtg.isSum();
+ }
+ return false;
+ }
+
private static boolean isSimpleValueFunction(Ptg token) {
if (token instanceof AbstractFunctionPtg) {
AbstractFunctionPtg aptg = (AbstractFunctionPtg) token;