diff --git a/src/java/org/apache/poi/hssf/model/FormulaParser.java b/src/java/org/apache/poi/hssf/model/FormulaParser.java index a021803b6..78bd113d4 100644 --- a/src/java/org/apache/poi/hssf/model/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/model/FormulaParser.java @@ -307,15 +307,15 @@ public class FormulaParser { private Ptg getFunction(String name,byte numArgs) { Ptg retval = null; - retval = new FuncVarPtg(name,numArgs); - /** if (numArgs == 1 && name.equals("SUM")) { + //retval = new FuncVarPtg(name,numArgs); + if (name.equals("IF")) { AttrPtg ptg = new AttrPtg(); - ptg.setData((short)1); //sums don't care but this is what excel does. - ptg.setSum(true); + ptg.setData((short)6); //sums don't care but this is what excel does. + ptg.setOptimizedIf(true); retval = ptg; } else { retval = new FuncVarPtg(name,numArgs); - }*/ + } return retval; } @@ -394,12 +394,13 @@ public class FormulaParser { /** Parse and Translate a Math Term */ private void Term(){ Factor(); - while (Look == '*' || Look == '/' || Look == '^' || Look == '&') { + while (Look == '*' || Look == '/' || Look == '^' || Look == '&' || Look == '=' ) { ///TODO do we need to do anything here?? if (Look == '*') Multiply(); if (Look == '/') Divide(); if (Look == '^') Power(); if (Look == '&') Concat(); + if (Look == '=') Equal(); } } @@ -410,14 +411,19 @@ public class FormulaParser { tokens.add(new AddPtg()); } - /** Recognize and Translate an Add */ + /** Recognize and Translate a Concatination */ private void Concat() { Match('&'); Term(); tokens.add(new ConcatPtg()); } - + /** Recognize and Translate a test for Equality */ + private void Equal() { + Match('='); + Term(); + tokens.add(new EqualPtg()); + } /** Recognize and Translate a Subtract */ private void Subtract() { diff --git a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java index 58eb98084..007d97ed3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java @@ -21,8 +21,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg { protected byte field_1_num_args; protected short field_2_fnc_index; - - + public String toString() { StringBuffer buffer = new StringBuffer(); buffer @@ -45,7 +44,11 @@ public abstract class AbstractFunctionPtg extends OperationPtg { } public String getName() { + if(field_2_fnc_index != 1) { return lookupName(field_2_fnc_index); + } else { + return "Funky case of formula recombinating"; + } } public String toFormulaString(SheetReferences refs) { @@ -54,15 +57,21 @@ public abstract class AbstractFunctionPtg extends OperationPtg { public String toFormulaString(String[] operands) { StringBuffer buf = new StringBuffer(); - buf.append(getName()+"("); - if (operands.length >0) { - for (int i=0;i0) { + for (int i=0;i