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:
Andrew C. Oliver 2002-09-02 21:16:29 +00:00
parent 72965e9a0d
commit a00135ad17
4 changed files with 44 additions and 20 deletions

View File

@ -307,15 +307,15 @@ public class FormulaParser {
private Ptg getFunction(String name,byte numArgs) { private Ptg getFunction(String name,byte numArgs) {
Ptg retval = null; Ptg retval = null;
retval = new FuncVarPtg(name,numArgs); //retval = new FuncVarPtg(name,numArgs);
/** if (numArgs == 1 && name.equals("SUM")) { if (name.equals("IF")) {
AttrPtg ptg = new AttrPtg(); AttrPtg ptg = new AttrPtg();
ptg.setData((short)1); //sums don't care but this is what excel does. ptg.setData((short)6); //sums don't care but this is what excel does.
ptg.setSum(true); ptg.setOptimizedIf(true);
retval = ptg; retval = ptg;
} else { } else {
retval = new FuncVarPtg(name,numArgs); retval = new FuncVarPtg(name,numArgs);
}*/ }
return retval; return retval;
} }
@ -394,12 +394,13 @@ public class FormulaParser {
/** Parse and Translate a Math Term */ /** Parse and Translate a Math Term */
private void Term(){ private void Term(){
Factor(); Factor();
while (Look == '*' || Look == '/' || Look == '^' || Look == '&') { while (Look == '*' || Look == '/' || Look == '^' || Look == '&' || Look == '=' ) {
///TODO do we need to do anything here?? ///TODO do we need to do anything here??
if (Look == '*') Multiply(); if (Look == '*') Multiply();
if (Look == '/') Divide(); if (Look == '/') Divide();
if (Look == '^') Power(); if (Look == '^') Power();
if (Look == '&') Concat(); if (Look == '&') Concat();
if (Look == '=') Equal();
} }
} }
@ -410,14 +411,19 @@ public class FormulaParser {
tokens.add(new AddPtg()); tokens.add(new AddPtg());
} }
/** Recognize and Translate an Add */ /** Recognize and Translate a Concatination */
private void Concat() { private void Concat() {
Match('&'); Match('&');
Term(); Term();
tokens.add(new ConcatPtg()); 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 */ /** Recognize and Translate a Subtract */
private void Subtract() { private void Subtract() {

View File

@ -21,8 +21,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
protected byte field_1_num_args; protected byte field_1_num_args;
protected short field_2_fnc_index; protected short field_2_fnc_index;
public String toString() { public String toString() {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer buffer
@ -45,7 +44,11 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
} }
public String getName() { public String getName() {
if(field_2_fnc_index != 1) {
return lookupName(field_2_fnc_index); return lookupName(field_2_fnc_index);
} else {
return "Funky case of formula recombinating";
}
} }
public String toFormulaString(SheetReferences refs) { public String toFormulaString(SheetReferences refs) {
@ -54,15 +57,21 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
public String toFormulaString(String[] operands) { public String toFormulaString(String[] operands) {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
buf.append(getName()+"("); if (field_2_fnc_index != 1) {
if (operands.length >0) { buf.append(getName()+"(");
for (int i=0;i<operands.length;i++) { if (operands.length >0) {
buf.append(operands[i]); for (int i=0;i<operands.length;i++) {
buf.append(','); buf.append(operands[i]);
} buf.append(',');
buf.deleteCharAt(buf.length()-1); }
} buf.deleteCharAt(buf.length()-1);
}
buf.append(")"); buf.append(")");
} else {
throw new RuntimeException("FUNKY CASE OF FORMULA RECOMBINATION NOT "+
"YET IMPLEMENTED");
}
return buf.toString(); return buf.toString();
} }

View File

@ -142,6 +142,10 @@ public class AttrPtg
field_1_options=sum.setByteBoolean(field_1_options,bsum); 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 // lets hope no one uses this anymore
public boolean isBaxcel() public boolean isBaxcel()
{ {
@ -196,8 +200,9 @@ public class AttrPtg
public String toFormulaString(String[] operands) { public String toFormulaString(String[] operands) {
if(space.isSet(field_1_options)) { if(space.isSet(field_1_options)) {
return operands[ 0 ]; return operands[ 0 ];
} } else if (optiIf.isSet(field_1_options)) {
else { return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] +")";
} else {
return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")"; return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")";
} }
} }

View File

@ -167,6 +167,10 @@ public abstract class Ptg
case PowerPtg.sid : case PowerPtg.sid :
retval = new PowerPtg(data, offset); retval = new PowerPtg(data, offset);
break; break;
case EqualPtg.sid:
retval = new EqualPtg(data, offset);
break;
case ConcatPtg.sid : case ConcatPtg.sid :
retval = new ConcatPtg(data, offset); retval = new ConcatPtg(data, offset);