preliminary support for "if" formulas. Doesn't work yet because of this
strange "aggregate this stuff" function PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352834 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72965e9a0d
commit
a00135ad17
@ -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() {
|
||||
|
@ -22,7 +22,6 @@ 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,6 +57,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
|
||||
|
||||
public String toFormulaString(String[] operands) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
if (field_2_fnc_index != 1) {
|
||||
buf.append(getName()+"(");
|
||||
if (operands.length >0) {
|
||||
for (int i=0;i<operands.length;i++) {
|
||||
@ -63,6 +67,11 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
|
||||
buf.deleteCharAt(buf.length()-1);
|
||||
}
|
||||
buf.append(")");
|
||||
} else {
|
||||
throw new RuntimeException("FUNKY CASE OF FORMULA RECOMBINATION NOT "+
|
||||
"YET IMPLEMENTED");
|
||||
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,10 @@ public class AttrPtg
|
||||
field_1_options=sum.setByteBoolean(field_1_options,bsum);
|
||||
}
|
||||
|
||||
public void setOptimizedIf(boolean bif) {
|
||||
field_1_options=optiIf.setByteBoolean(field_1_options,bif);
|
||||
}
|
||||
|
||||
// lets hope no one uses this anymore
|
||||
public boolean isBaxcel()
|
||||
{
|
||||
@ -196,8 +200,9 @@ public class AttrPtg
|
||||
public String toFormulaString(String[] operands) {
|
||||
if(space.isSet(field_1_options)) {
|
||||
return operands[ 0 ];
|
||||
}
|
||||
else {
|
||||
} else if (optiIf.isSet(field_1_options)) {
|
||||
return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] +")";
|
||||
} else {
|
||||
return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")";
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,10 @@ public abstract class Ptg
|
||||
retval = new PowerPtg(data, offset);
|
||||
break;
|
||||
|
||||
case EqualPtg.sid:
|
||||
retval = new EqualPtg(data, offset);
|
||||
break;
|
||||
|
||||
case ConcatPtg.sid :
|
||||
retval = new ConcatPtg(data, offset);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user