View | Details | Raw Unified | Return to bug 34828
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java (+70 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import java.lang.reflect.Constructor;
8
9
import org.apache.poi.hssf.record.formula.AddPtg;
10
import org.apache.poi.hssf.record.formula.Ptg;
11
12
/**
13
 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
14
 *
15
 */
16
public class AddEval implements OperationEval {
17
18
    private AddPtg delegate;
19
    
20
    public AddEval(Ptg ptg) {
21
        delegate = (AddPtg) ptg;
22
    }
23
    
24
25
    
26
    /* (non-Javadoc)
27
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
28
     */
29
    public Eval evaluate(Eval[] operands) {
30
        double d = 0;
31
        Eval retval = null;
32
    	for (int i=0, iSize=getNumberOfOperands(); i<iSize; i++) {
33
        	if (operands[i] instanceof NumericValueEval) {
34
        		d += ((NumericValueEval) operands[i]).getNumberValue();
35
        	}
36
        	else if (operands[i] instanceof RefEval) {
37
        	    RefEval re = (RefEval) operands[i];
38
        	    ValueEval ve = (ValueEval) re.getInnerValueEval();
39
            	if (ve instanceof NumericValueEval) {
40
            		d += ((NumericValueEval) ve).getNumberValue();
41
            	}
42
            	else {
43
            	    retval = ErrorEval.ERROR_502;
44
            	    break;
45
            	}
46
        	}
47
        	else {
48
        	    retval = ErrorEval.ERROR_502;
49
        	    break;
50
        	}
51
    	}
52
    	if (retval == null) 
53
    	    retval = new NumberEval(d);
54
    	return retval;
55
    }
56
    
57
    /* (non-Javadoc)
58
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
59
     */
60
    public int getNumberOfOperands() {
61
        return delegate.getNumberOfOperands();
62
    }
63
    
64
    /* (non-Javadoc)
65
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
66
     */
67
    public int getType() {
68
        return delegate.getType();
69
    }
70
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java (+58 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.AreaPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class Area2DEval implements AreaEval {
15
16
    private AreaPtg delegate;
17
    private ValueEval[] values;
18
    
19
    public Area2DEval(Ptg ptg, ValueEval[] values) {
20
        this.delegate = (AreaPtg) ptg;
21
        this.values = values;
22
    }
23
    
24
    /* (non-Javadoc)
25
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstCol()
26
     */
27
    public short getFirstColumn() {
28
        return delegate.getFirstColumn();
29
    }
30
    
31
    /* (non-Javadoc)
32
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstRow()
33
     */
34
    public short getFirstRow() {
35
        return delegate.getFirstRow();
36
    }
37
    
38
    /* (non-Javadoc)
39
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastCol()
40
     */
41
    public short getLastColumn() {
42
        return delegate.getLastColumn();
43
    }
44
    
45
    /* (non-Javadoc)
46
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastRow()
47
     */
48
    public short getLastRow() {
49
        return delegate.getLastRow();
50
    }
51
    
52
    /* (non-Javadoc)
53
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getValues()
54
     */
55
    public ValueEval[] getValues() {
56
        return values;
57
    }
58
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java (+73 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import java.lang.reflect.Constructor;
8
9
import org.apache.poi.hssf.record.formula.Area3DPtg;
10
import org.apache.poi.hssf.record.formula.Ptg;
11
12
/**
13
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
14
 *
15
 */
16
public class Area3DEval implements AreaEval {
17
18
    private Area3DPtg delegate;
19
    
20
    private ValueEval[] values;
21
    
22
    public Area3DEval(Ptg ptg, ValueEval[] values) {
23
        this.values = values;
24
        this.delegate = (Area3DPtg) ptg;
25
    }
26
    
27
    
28
    public static void main(String[] args) throws Exception {
29
        Class clazz = Area3DEval.class;
30
        Constructor[] carr = clazz.getDeclaredConstructors();
31
        for (int i=0, iSize=carr.length; i<iSize; i++) {
32
            Object[] o = carr[i].getParameterTypes();
33
            for (int j=0, jSize=o.length; j<jSize; j++) {
34
                System.out.println(o[j]);
35
            }
36
        }
37
    }
38
    /* (non-Javadoc)
39
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstCol()
40
     */
41
    public short getFirstColumn() {
42
        return delegate.getFirstColumn();
43
    }
44
    
45
    /* (non-Javadoc)
46
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getFirstRow()
47
     */
48
    public short getFirstRow() {
49
        return delegate.getFirstRow();
50
    }
51
    
52
    /* (non-Javadoc)
53
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastCol()
54
     */
55
    public short getLastColumn() {
56
        return delegate.getLastColumn();
57
    }
58
    
59
    /* (non-Javadoc)
60
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getLastRow()
61
     */
62
    public short getLastRow() {
63
        return delegate.getLastRow();
64
    }
65
    
66
    /* (non-Javadoc)
67
     * @see org.apache.poi.hssf.record.formula.eval.AreaEval#getValues()
68
     */
69
    public ValueEval[] getValues() {
70
        return values;
71
    }
72
    
73
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java (+18 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public interface AreaEval extends Eval {
12
13
    public short getFirstRow();
14
    public short getLastRow();
15
    public short getFirstColumn();
16
    public short getLastColumn();
17
    public ValueEval[] getValues();
18
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java (+37 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.BoolPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class BoolEval implements NumericValueEval, StringValueEval {
15
16
    private boolean value;
17
    
18
    public BoolEval(Ptg ptg) {
19
        this.value = ((BoolPtg) ptg).getValue();
20
    }
21
    
22
    public BoolEval(boolean value) {
23
        this.value = value;
24
    }
25
    
26
    public boolean getBooleanValue() {
27
        return value;
28
    }
29
    
30
    public double getNumberValue() {
31
        return value ? (short) 1 : (short) 0;
32
    }
33
    
34
    public String getStringValue() {
35
        return value ? "1" : "0";
36
    }
37
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java (+54 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.ConcatPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class ConcatEval implements OperationEval {
15
16
    private ConcatPtg delegate;
17
    
18
    public ConcatEval(Ptg ptg) {
19
        this.delegate = (ConcatPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        Eval retval = null;
27
        if (operands.length == getNumberOfOperands()) {
28
            StringBuffer sb = new StringBuffer();
29
            for (int i=0, iSize=operands.length; i<iSize; i++) {
30
                if (operands[i] instanceof StringValueEval) {
31
                    sb.append(operands[i]);
32
                }
33
            }
34
        }
35
        else {
36
            retval = ErrorEval.ERROR_UNKNOWN;
37
        }
38
        return retval;
39
    }
40
    
41
    /* (non-Javadoc)
42
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
43
     */
44
    public int getNumberOfOperands() {
45
        return delegate.getNumberOfOperands();
46
    }
47
    
48
    /* (non-Javadoc)
49
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
50
     */
51
    public int getType() {
52
        return delegate.getType();
53
    }
54
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java (+82 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.DividePtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class DivideEval implements OperationEval {
15
16
    private DividePtg delegate;
17
    
18
    public DivideEval(Ptg ptg) {
19
        this.delegate = (DividePtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        double d0 = 0;
27
        double d1 = 0;
28
		ValueEval retval = null;
29
		if (operands.length == 2) {
30
		    if (operands[0] != null) {
31
				if (operands[0] instanceof NumericValueEval) {
32
				    d0 = ((NumericValueEval) operands[0]).getNumberValue();
33
				}
34
				else if (operands[0] instanceof StringValueEval) {
35
				    retval = ErrorEval.ERROR_502;
36
				}
37
				else if (operands[0] instanceof ErrorEval) {
38
				    retval = (ErrorEval) operands[0];
39
				}
40
				else {
41
				    retval = ErrorEval.INVALID_VALUE;
42
				}
43
		    }
44
		    if (retval == null && operands[1] != null) {
45
				if (operands[1] instanceof NumericValueEval) {
46
				    d1 = ((NumericValueEval) operands[1]).getNumberValue();
47
				}
48
				else if (operands[1] instanceof StringValueEval) {
49
				    retval = ErrorEval.ERROR_502;
50
				}
51
				else if (operands[0] instanceof ErrorEval) {
52
				    ErrorEval e = (ErrorEval) operands[0];
53
				    retval = e;
54
				}
55
				else {
56
				    retval = ErrorEval.INVALID_VALUE;
57
				}
58
		    }
59
			if (retval != null)
60
			    retval = new NumberEval(d0/d1);
61
		}
62
		else {
63
		    retval = ErrorEval.ERROR_UNKNOWN;
64
		}
65
		return retval;
66
    }
67
    
68
    /* (non-Javadoc)
69
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
70
     */
71
    public int getNumberOfOperands() {
72
        return delegate.getNumberOfOperands();
73
    }
74
    
75
    /* (non-Javadoc)
76
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
77
     */
78
    public int getType() {
79
        return delegate.getType();
80
    }
81
82
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java (+43 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.EqualPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class EqualEval implements OperationEval {
15
16
    private EqualPtg delegate;
17
    
18
    public EqualEval(Ptg ptg) {
19
        this.delegate = (EqualPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java (+64 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public class ErrorEval implements ValueEval {
12
13
    private int errorCode;
14
    
15
    // Oo std error codes
16
    public static final ErrorEval ERROR_501 = new ErrorEval(501);
17
    public static final ErrorEval ERROR_502 = new ErrorEval(502);
18
    public static final ErrorEval ERROR_503 = new ErrorEval(503);
19
    public static final ErrorEval ERROR_504 = new ErrorEval(504);
20
    public static final ErrorEval ERROR_505 = new ErrorEval(505);
21
    public static final ErrorEval ERROR_506 = new ErrorEval(506);
22
    public static final ErrorEval ERROR_507 = new ErrorEval(507);
23
    public static final ErrorEval ERROR_508 = new ErrorEval(508);
24
    public static final ErrorEval ERROR_509 = new ErrorEval(509);
25
    public static final ErrorEval ERROR_510 = new ErrorEval(510);
26
    public static final ErrorEval ERROR_511 = new ErrorEval(511);
27
    public static final ErrorEval ERROR_512 = new ErrorEval(512);
28
    public static final ErrorEval ERROR_513 = new ErrorEval(513);
29
    public static final ErrorEval ERROR_514 = new ErrorEval(514);
30
    public static final ErrorEval ERROR_515 = new ErrorEval(515);
31
    public static final ErrorEval ERROR_516 = new ErrorEval(516);
32
    public static final ErrorEval ERROR_517 = new ErrorEval(517);
33
    public static final ErrorEval ERROR_518 = new ErrorEval(518);
34
    public static final ErrorEval ERROR_519 = new ErrorEval(519);
35
    public static final ErrorEval ERROR_520 = new ErrorEval(520);
36
    public static final ErrorEval ERROR_521 = new ErrorEval(521);
37
    public static final ErrorEval ERROR_522 = new ErrorEval(522);
38
    public static final ErrorEval ERROR_523 = new ErrorEval(523);
39
    public static final ErrorEval ERROR_524 = new ErrorEval(524);
40
    public static final ErrorEval ERROR_525 = new ErrorEval(525);
41
    public static final ErrorEval ERROR_526 = new ErrorEval(526);
42
    public static final ErrorEval ERROR_527 = new ErrorEval(527);
43
    public static final ErrorEval INVALID_NAME = ERROR_525;
44
    public static final ErrorEval INVALID_VALUE = ERROR_519;
45
46
    
47
    // Non std error codes
48
    public static final ErrorEval ERROR_UNKNOWN = new ErrorEval(-20);
49
    public static final ErrorEval FUNCTION_NOT_IMPLEMENTED = new ErrorEval(-30);
50
    
51
    
52
    private ErrorEval(int errorCode) {
53
        this.errorCode = errorCode;
54
    }
55
    
56
    public int getErrorCode() {
57
        return errorCode;
58
    }
59
    
60
    public String getStringValue() {
61
        return "Err:"+Integer.toString(errorCode);
62
    }
63
64
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.java (+14 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public interface Eval {
12
13
    
14
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.java (+56 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
import org.apache.poi.hssf.record.formula.functions.Function;
10
11
/**
12
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
13
 *
14
 */
15
public class FuncVarEval extends FunctionEval {
16
17
    private AbstractFunctionPtg delegate;
18
    
19
    public FuncVarEval(Ptg funcPtg) {
20
        delegate = (AbstractFunctionPtg) funcPtg;
21
    }
22
    
23
    /* (non-Javadoc)
24
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
25
     */
26
    public Eval evaluate(Eval[] operands) {
27
        Eval retval = null;
28
		Function f = getFunction();
29
		if (f!=null)
30
		    retval = f.evaluate(operands);
31
		else 
32
		    retval = ErrorEval.FUNCTION_NOT_IMPLEMENTED;
33
		return retval;
34
    }
35
    
36
    /* (non-Javadoc)
37
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
38
     */
39
    public int getNumberOfOperands() {
40
        return delegate.getNumberOfOperands();
41
    }
42
    
43
    /* (non-Javadoc)
44
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
45
     */
46
    public int getType() {
47
        return delegate.getType();
48
    }
49
    
50
    /* (non-Javadoc)
51
     * @see org.apache.poi.hssf.record.formula.eval.FunctionEval#getFunctionIndex()
52
     */
53
    public short getFunctionIndex() {
54
        return delegate.getFunctionIndex();
55
    }
56
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java (+377 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.functions.*;
8
9
/**
10
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 */
13
public abstract class FunctionEval implements OperationEval {
14
    protected static Function[] functions = produceFunctions();
15
    public Function getFunction() {
16
    	short fidx = getFunctionIndex();
17
    	return functions[fidx];
18
    }
19
    public abstract short getFunctionIndex();
20
21
    private static Function[] produceFunctions() {
22
        Function[] retval = new Function[368];
23
    	retval[0]  = new Count();	//	COUNT
24
    	retval[1]  = null;	//	specialflag
25
    	retval[2]  = new IsNa();	//	ISNA
26
    	retval[3]  = new IsError();	//	ISERROR
27
    	retval[4]  = new Sum();	//	SUM
28
    	retval[5]  = new Average();	//	AVERAGE
29
    	retval[6]  = new Min();	//	MIN
30
    	retval[7]  = new Max();	//	MAX
31
    	retval[8]  = new Row();	//	ROW
32
    	retval[9]  = new Column();	//	COLUMN
33
    	retval[10] = new Na();	//	NA
34
    	retval[11] = new Npv();	//	NPV
35
    	retval[12] = new Stdev();	//	STDEV
36
    	retval[13] = new Dollar();	//	DOLLAR
37
    	retval[14] = new Fixed();	//	FIXED
38
    	retval[15] = new Sin();	//	SIN
39
    	retval[16] = new Cos();	//	COS
40
    	retval[17] = new Tan();	//	TAN
41
    	retval[18] = new Atan();	//	ATAN
42
    	retval[19] = new Pi();	//	PI
43
    	retval[20] = new Sqrt();	//	SQRT
44
    	retval[21] = new Exp();	//	EXP
45
    	retval[22] = new Ln();	//	LN
46
    	retval[23] = new Log10();	//	LOG10
47
    	retval[24] = new Abs();	//	ABS
48
    	retval[25] = new Int();	//	INT
49
    	retval[26] = new Sign();	//	SIGN
50
    	retval[27] = new Round();	//	ROUND
51
    	retval[28] = null;	//	LOOKUP
52
    	retval[29] = null;	//	INDEX
53
    	retval[30] = null;	//	REPT
54
    	retval[31] = null;	//	MID
55
    	retval[32] = null;	//	LEN
56
    	retval[33] = null;	//	VALUE
57
    	retval[34] = null;	//	TRUE
58
    	retval[35] = null;	//	FALSE
59
    	retval[36] = null;	//	AND
60
    	retval[37] = null;	//	OR
61
    	retval[38] = null;	//	NOT
62
    	retval[39] = null;	//	MOD
63
    	retval[40] = null;	//	DCOUNT
64
    	retval[41] = null;	//	DSUM
65
    	retval[42] = null;	//	DAVERAGE
66
    	retval[43] = null;	//	DMIN
67
    	retval[44] = null;	//	DMAX
68
    	retval[45] = null;	//	DSTDEV
69
    	retval[46] = null;	//	VAR
70
    	retval[47] = null;	//	DVAR
71
    	retval[48] = null;	//	TEXT
72
    	retval[49] = null;	//	LINEST
73
    	retval[50] = null;	//	TREND
74
    	retval[51] = null;	//	LOGEST
75
    	retval[52] = null;	//	GROWTH
76
    	retval[53] = null;	//	GOTO
77
    	retval[54] = null;	//	HALT
78
    	retval[55] = null;	//	PV
79
    	retval[56] = null;	//	FV
80
    	retval[57] = null;	//	NPER
81
    	retval[58] = null;	//	PMT
82
    	retval[59] = null;	//	RATE
83
    	retval[60] = null;	//	MIRR
84
    	retval[61] = null;	//	IRR
85
    	retval[62] = null;	//	RAND
86
    	retval[63] = null;	//	MATCH
87
    	retval[64] = null;	//	DATE
88
    	retval[65] = null;	//	TIME
89
    	retval[66] = null;	//	DAY
90
    	retval[67] = null;	//	MONTH
91
    	retval[68] = null;	//	YEAR
92
    	retval[69] = null;	//	WEEKDAY
93
    	retval[70] = null;	//	HOUR
94
    	retval[71] = null;	//	MINUTE
95
    	retval[72] = null;	//	SECOND
96
    	retval[73] = null;	//	NOW
97
    	retval[74] = null;	//	AREAS
98
    	retval[75] = null;	//	ROWS
99
    	retval[76] = null;	//	COLUMNS
100
    	retval[77] = null;	//	OFFSET
101
    	retval[78] = null;	//	ABSREF
102
    	retval[79] = null;	//	RELREF
103
    	retval[80] = null;	//	ARGUMENT
104
    	retval[81] = null;	//	SEARCH
105
    	retval[82] = null;	//	TRANSPOSE
106
    	retval[83] = null;	//	ERROR
107
    	retval[84] = null;	//	STEP
108
    	retval[85] = null;	//	TYPE
109
    	retval[86] = null;	//	ECHO
110
    	retval[87] = null;	//	SETNAME
111
    	retval[88] = null;	//	CALLER
112
    	retval[89] = null;	//	DEREF
113
    	retval[90] = null;	//	WINDOWS
114
    	retval[91] = null;	//	SERIES
115
    	retval[92] = null;	//	DOCUMENTS
116
    	retval[93] = null;	//	ACTIVECELL
117
    	retval[94] = null;	//	SELECTION
118
    	retval[95] = null;	//	RESULT
119
    	retval[96] = null;	//	ATAN2
120
    	retval[97] = null;	//	ASIN
121
    	retval[98] = null;	//	ACOS
122
    	retval[99] = null;	//	CHOOSE
123
    	retval[100] = null;	//	HLOOKUP
124
    	retval[101] = null;	//	VLOOKUP
125
    	retval[102] = null;	//	LINKS
126
    	retval[103] = null;	//	INPUT
127
    	retval[104] = null;	//	ISREF
128
    	retval[105] = null;	//	GETFORMULA
129
    	retval[106] = null;	//	GETNAME
130
    	retval[107] = null;	//	SETVALUE
131
    	retval[108] = null;	//	LOG
132
    	retval[109] = null;	//	EXEC
133
    	retval[110] = null;	//	CHAR
134
    	retval[111] = null;	//	LOWER
135
    	retval[112] = null;	//	UPPER
136
    	retval[113] = null;	//	PROPER
137
    	retval[114] = null;	//	LEFT
138
    	retval[115] = null;	//	RIGHT
139
    	retval[116] = null;	//	EXACT
140
    	retval[117] = null;	//	TRIM
141
    	retval[118] = null;	//	REPLACE
142
    	retval[119] = null;	//	SUBSTITUTE
143
    	retval[120] = null;	//	CODE
144
    	retval[121] = null;	//	NAMES
145
    	retval[122] = null;	//	DIRECTORY
146
    	retval[123] = null;	//	FIND
147
    	retval[124] = null;	//	CELL
148
    	retval[125] = null;	//	ISERR
149
    	retval[126] = null;	//	ISTEXT
150
    	retval[127] = null;	//	ISNUMBER
151
    	retval[128] = null;	//	ISBLANK
152
    	retval[129] = null;	//	T
153
    	retval[130] = null;	//	N
154
    	retval[131] = null;	//	FOPEN
155
    	retval[132] = null;	//	FCLOSE
156
    	retval[133] = null;	//	FSIZE
157
    	retval[134] = null;	//	FREADLN
158
    	retval[135] = null;	//	FREAD
159
    	retval[136] = null;	//	FWRITELN
160
    	retval[137] = null;	//	FWRITE
161
    	retval[138] = null;	//	FPOS
162
    	retval[139] = null;	//	DATEVALUE
163
    	retval[140] = null;	//	TIMEVALUE
164
    	retval[141] = null;	//	SLN
165
    	retval[142] = null;	//	SYD
166
    	retval[143] = null;	//	DDB
167
    	retval[144] = null;	//	GETDEF
168
    	retval[145] = null;	//	REFTEXT
169
    	retval[146] = null;	//	TEXTREF
170
    	retval[147] = null;	//	INDIRECT
171
    	retval[148] = null;	//	REGISTER
172
    	retval[149] = null;	//	CALL
173
    	retval[150] = null;	//	ADDBAR
174
    	retval[151] = null;	//	ADDMENU
175
    	retval[152] = null;	//	ADDCOMMAND
176
    	retval[153] = null;	//	ENABLECOMMAND
177
    	retval[154] = null;	//	CHECKCOMMAND
178
    	retval[155] = null;	//	RENAMECOMMAND
179
    	retval[156] = null;	//	SHOWBAR
180
    	retval[157] = null;	//	DELETEMENU
181
    	retval[158] = null;	//	DELETECOMMAND
182
    	retval[159] = null;	//	GETCHARTITEM
183
    	retval[160] = null;	//	DIALOGBOX
184
    	retval[161] = null;	//	CLEAN
185
    	retval[162] = null;	//	MDETERM
186
    	retval[163] = null;	//	MINVERSE
187
    	retval[164] = null;	//	MMULT
188
    	retval[165] = null;	//	FILES
189
    	retval[166] = null;	//	IPMT
190
    	retval[167] = null;	//	PPMT
191
    	retval[168] = null;	//	COUNTA
192
    	retval[169] = null;	//	CANCELKEY
193
    	retval[170] = null;	//	INITIATE
194
    	retval[171] = null;	//	REQUEST
195
    	retval[172] = null;	//	POKE
196
    	retval[173] = null;	//	EXECUTE
197
    	retval[174] = null;	//	TERMINATE
198
    	retval[175] = null;	//	RESTART
199
    	retval[176] = null;	//	HELP
200
    	retval[177] = null;	//	GETBAR
201
    	retval[178] = null;	//	PRODUCT
202
    	retval[179] = null;	//	FACT
203
    	retval[180] = null;	//	GETCELL
204
    	retval[181] = null;	//	GETWORKSPACE
205
    	retval[182] = null;	//	GETWINDOW
206
    	retval[183] = null;	//	GETDOCUMENT
207
    	retval[184] = null;	//	DPRODUCT
208
    	retval[185] = null;	//	ISNONTEXT
209
    	retval[186] = null;	//	GETNOTE
210
    	retval[187] = null;	//	NOTE
211
    	retval[188] = null;	//	STDEVP
212
    	retval[189] = null;	//	VARP
213
    	retval[190] = null;	//	DSTDEVP
214
    	retval[191] = null;	//	DVARP
215
    	retval[192] = null;	//	TRUNC
216
    	retval[193] = null;	//	ISLOGICAL
217
    	retval[194] = null;	//	DCOUNTA
218
    	retval[195] = null;	//	DELETEBAR
219
    	retval[196] = null;	//	UNREGISTER
220
    	retval[197] = null;	//	USDOLLAR
221
    	retval[198] = null;	//	FINDB
222
    	retval[199] = null;	//	SEARCHB
223
    	retval[200] = null;	//	REPLACEB
224
    	retval[201] = null;	//	LEFTB
225
    	retval[202] = null;	//	RIGHTB
226
    	retval[203] = null;	//	MIDB
227
    	retval[204] = null;	//	LENB
228
    	retval[205] = null;	//	ROUNDUP
229
    	retval[206] = null;	//	ROUNDDOWN
230
    	retval[207] = null;	//	ASC
231
    	retval[208] = null;	//	DBCS
232
    	retval[209] = null;	//	RANK
233
    	retval[210] = null;	//	ADDRESS
234
    	retval[211] = null;	//	DAYS360
235
    	retval[212] = null;	//	TODAY
236
    	retval[213] = null;	//	VDB
237
    	retval[214] = null;	//	MEDIAN
238
    	retval[215] = null;	//	SUMPRODUCT
239
    	retval[216] = null;	//	SINH
240
    	retval[217] = null;	//	COSH
241
    	retval[218] = null;	//	TANH
242
    	retval[219] = null;	//	ASINH
243
    	retval[220] = null;	//	ACOSH
244
    	retval[221] = null;	//	ATANH
245
    	retval[222] = null;	//	DGET
246
    	retval[223] = null;	//	CREATEOBJECT
247
    	retval[224] = null;	//	VOLATILE
248
    	retval[225] = null;	//	LASTERROR
249
    	retval[226] = null;	//	CUSTOMUNDO
250
    	retval[227] = null;	//	CUSTOMREPEAT
251
    	retval[228] = null;	//	FORMULACONVERT
252
    	retval[229] = null;	//	GETLINKINFO
253
    	retval[230] = null;	//	TEXTBOX
254
    	retval[231] = null;	//	INFO
255
    	retval[232] = null;	//	GROUP
256
    	retval[233] = null;	//	GETOBJECT
257
    	retval[234] = null;	//	DB
258
    	retval[235] = null;	//	PAUSE
259
    	retval[236] = null;	//	RESUME
260
    	retval[237] = null;	//	FREQUENCY
261
    	retval[238] = null;	//	ADDTOOLBAR
262
    	retval[239] = null;	//	DELETETOOLBAR
263
    	retval[240] = null;	//	externalflag
264
    	retval[241] = null;	//	RESETTOOLBAR
265
    	retval[242] = null;	//	EVALUATE
266
    	retval[243] = null;	//	GETTOOLBAR
267
    	retval[244] = null;	//	GETTOOL
268
    	retval[245] = null;	//	SPELLINGCHECK
269
    	retval[246] = null;	//	ERRORTYPE
270
    	retval[247] = null;	//	APPTITLE
271
    	retval[248] = null;	//	WINDOWTITLE
272
    	retval[249] = null;	//	SAVETOOLBAR
273
    	retval[250] = null;	//	ENABLETOOL
274
    	retval[251] = null;	//	PRESSTOOL
275
    	retval[252] = null;	//	REGISTERID
276
    	retval[253] = null;	//	GETWORKBOOK
277
    	retval[254] = null;	//	AVEDEV
278
    	retval[255] = null;	//	BETADIST
279
    	retval[256] = null;	//	GAMMALN
280
    	retval[257] = null;	//	BETAINV
281
    	retval[258] = null;	//	BINOMDIST
282
    	retval[259] = null;	//	CHIDIST
283
    	retval[260] = null;	//	CHIINV
284
    	retval[261] = null;	//	COMBIN
285
    	retval[262] = null;	//	CONFIDENCE
286
    	retval[263] = null;	//	CRITBINOM
287
    	retval[264] = null;	//	EVEN
288
    	retval[265] = null;	//	EXPONDIST
289
    	retval[266] = null;	//	FDIST
290
    	retval[267] = null;	//	FINV
291
    	retval[268] = null;	//	FISHER
292
    	retval[269] = null;	//	FISHERINV
293
    	retval[270] = null;	//	FLOOR
294
    	retval[271] = null;	//	GAMMADIST
295
    	retval[272] = null;	//	GAMMAINV
296
    	retval[273] = null;	//	CEILING
297
    	retval[274] = null;	//	HYPGEOMDIST
298
    	retval[275] = null;	//	LOGNORMDIST
299
    	retval[276] = null;	//	LOGINV
300
    	retval[277] = null;	//	NEGBINOMDIST
301
    	retval[278] = null;	//	NORMDIST
302
    	retval[279] = null;	//	NORMSDIST
303
    	retval[280] = null;	//	NORMINV
304
    	retval[281] = null;	//	NORMSINV
305
    	retval[282] = null;	//	STANDARDIZE
306
    	retval[283] = null;	//	ODD
307
    	retval[284] = null;	//	PERMUT
308
    	retval[285] = null;	//	POISSON
309
    	retval[286] = null;	//	TDIST
310
    	retval[287] = null;	//	WEIBULL
311
    	retval[288] = null;	//	SUMXMY2
312
    	retval[289] = null;	//	SUMX2MY2
313
    	retval[290] = null;	//	SUMX2PY2
314
    	retval[291] = null;	//	CHITEST
315
    	retval[292] = null;	//	CORREL
316
    	retval[293] = null;	//	COVAR
317
    	retval[294] = null;	//	FORECAST
318
    	retval[295] = null;	//	FTEST
319
    	retval[296] = null;	//	INTERCEPT
320
    	retval[297] = null;	//	PEARSON
321
    	retval[298] = null;	//	RSQ
322
    	retval[299] = null;	//	STEYX
323
    	retval[300] = null;	//	SLOPE
324
    	retval[301] = null;	//	TTEST
325
    	retval[302] = null;	//	PROB
326
    	retval[303] = null;	//	DEVSQ
327
    	retval[304] = null;	//	GEOMEAN
328
    	retval[305] = null;	//	HARMEAN
329
    	retval[306] = null;	//	SUMSQ
330
    	retval[307] = null;	//	KURT
331
    	retval[308] = null;	//	SKEW
332
    	retval[309] = null;	//	ZTEST
333
    	retval[310] = null;	//	LARGE
334
    	retval[311] = null;	//	SMALL
335
    	retval[312] = null;	//	QUARTILE
336
    	retval[313] = null;	//	PERCENTILE
337
    	retval[314] = null;	//	PERCENTRANK
338
    	retval[315] = null;	//	MODE
339
    	retval[316] = null;	//	TRIMMEAN
340
    	retval[317] = null;	//	TINV
341
    	retval[318] = null;	//	MOVIECOMMAND
342
    	retval[319] = null;	//	GETMOVIE
343
    	retval[320] = null;	//	CONCATENATE
344
    	retval[321] = null;	//	POWER
345
    	retval[322] = null;	//	PIVOTADDDATA
346
    	retval[323] = null;	//	GETPIVOTTABLE
347
    	retval[324] = null;	//	GETPIVOTFIELD
348
    	retval[325] = null;	//	GETPIVOTITEM
349
    	retval[326] = null;	//	RADIANS
350
    	retval[327] = null;	//	DEGREES
351
    	retval[328] = null;	//	SUBTOTAL
352
    	retval[329] = null;	//	SUMIF
353
    	retval[330] = null;	//	COUNTIF
354
    	retval[331] = null;	//	COUNTBLANK
355
    	retval[332] = null;	//	SCENARIOGET
356
    	retval[333] = null;	//	OPTIONSLISTSGET
357
    	retval[334] = null;	//	ISPMT
358
    	retval[335] = null;	//	DATEDIF
359
    	retval[336] = null;	//	DATESTRING
360
    	retval[337] = null;	//	NUMBERSTRING
361
    	retval[338] = null;	//	ROMAN
362
    	retval[339] = null;	//	OPENDIALOG
363
    	retval[340] = null;	//	SAVEDIALOG
364
    	retval[341] = null;	//	VIEWGET
365
    	retval[342] = null;	//	GETPIVOTDATA
366
    	retval[343] = null;	//	HYPERLINK
367
    	retval[344] = null;	//	PHONETIC
368
    	retval[345] = null;	//	AVERAGEA
369
    	retval[346] = null;	//	MAXA
370
    	retval[347] = null;	//	MINA
371
    	retval[348] = null;	//	STDEVPA
372
    	retval[349] = null;	//	VARPA
373
    	retval[350] = null;	//	STDEVA
374
    	retval[351] = null;	//	VARA
375
    	return retval;
376
    }
377
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java (+50 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class GreaterEqualEval implements OperationEval {
15
16
    private GreaterEqualPtg delegate;
17
    
18
    public GreaterEqualEval(Ptg ptg) {
19
        this.delegate = (GreaterEqualPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        boolean b = false;
27
        double d0 = 0;
28
        double d1 = 0;
29
        if (operands[0] instanceof NumericValueEval) {
30
            
31
        }
32
        
33
        return new BoolEval(b);
34
    }
35
    
36
    /* (non-Javadoc)
37
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
38
     */
39
    public int getNumberOfOperands() {
40
        return delegate.getNumberOfOperands();
41
    }
42
    
43
    /* (non-Javadoc)
44
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
45
     */
46
    public int getType() {
47
        return delegate.getType();
48
    }
49
50
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.GreaterThanPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class GreaterThanEval implements OperationEval {
15
16
    private GreaterThanPtg delegate;
17
    
18
    public GreaterThanEval(Ptg ptg) {
19
        this.delegate = (GreaterThanPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
    
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.LessEqualPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class LessEqualEval implements OperationEval {
15
16
    private LessEqualPtg delegate;
17
    
18
    public LessEqualEval(Ptg ptg) {
19
        this.delegate = (LessEqualPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
    
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.LessThanPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class LessThanEval implements OperationEval {
15
16
    private LessThanPtg delegate;
17
    
18
    public LessThanEval(Ptg ptg) {
19
        this.delegate = (LessThanPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
    
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java (+67 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.MultiplyPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class MultiplyEval implements OperationEval {
15
16
    private MultiplyPtg delegate;
17
    
18
    public MultiplyEval(Ptg ptg) {
19
        this.delegate = (MultiplyPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        double d = 0;
27
        Eval retval = null;
28
    	for (int i=0, iSize=getNumberOfOperands(); i<iSize; i++) {
29
        	if (operands[i] instanceof NumericValueEval) {
30
        		d *= ((NumericValueEval) operands[i]).getNumberValue();
31
        	}
32
        	else if (operands[i] instanceof RefEval) {
33
        	    RefEval re = (RefEval) operands[i];
34
        	    ValueEval ve = (ValueEval) re.getInnerValueEval();
35
            	if (ve instanceof NumericValueEval) {
36
            		d *= ((NumericValueEval) ve).getNumberValue();
37
            	}
38
            	else {
39
            	    retval = ErrorEval.ERROR_502;
40
            	    break;
41
            	}
42
        	}
43
        	else {
44
        	    retval = ErrorEval.ERROR_502;
45
        	    break;
46
        	}
47
    	}
48
    	if (retval == null) 
49
    	    retval = new NumberEval(d);
50
    	return retval;
51
    }
52
    
53
    /* (non-Javadoc)
54
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
55
     */
56
    public int getNumberOfOperands() {
57
        return delegate.getNumberOfOperands();
58
    }
59
    
60
    /* (non-Javadoc)
61
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
62
     */
63
    public int getType() {
64
        return delegate.getType();
65
    }
66
67
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.NotEqualPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class NotEqualEval implements OperationEval {
15
16
    private NotEqualPtg delegate;
17
    
18
    public NotEqualEval(Ptg ptg) {
19
        this.delegate = (NotEqualPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
    
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.IntPtg;
8
import org.apache.poi.hssf.record.formula.NumberPtg;
9
import org.apache.poi.hssf.record.formula.Ptg;
10
11
/**
12
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
13
 *
14
 */
15
public class NumberEval implements NumericValueEval, StringValueEval {
16
17
    private double value;
18
    
19
    
20
    public NumberEval(Ptg ptg) {
21
        if (ptg instanceof IntPtg) {
22
            this.value = ((IntPtg) ptg).getValue();
23
        }
24
        else if (ptg instanceof NumberPtg) {
25
            this.value = ((NumberPtg) ptg).getValue();
26
        }
27
    }
28
    
29
    public NumberEval(double value) {
30
        this.value = value;
31
    }
32
    
33
    public double getNumberValue() {
34
        return value;
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.StringValueEval#getStringValue()
39
     */
40
    public String getStringValue() {
41
        return String.valueOf(value);
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericValueEval.java (+14 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public interface NumericValueEval extends ValueEval {
12
13
    public abstract double getNumberValue();
14
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/OperationEval.java (+18 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public interface OperationEval extends Eval {
12
13
    public abstract Eval evaluate(Eval[] evals);
14
    
15
    public abstract int getNumberOfOperands();
16
    
17
    public abstract int getType();
18
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.PowerPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class PowerEval implements OperationEval {
15
16
    private PowerPtg delegate;
17
    
18
    public PowerEval(Ptg ptg) {
19
        this.delegate = (PowerPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        // TODO Auto-generated method stub
27
        return null;
28
    }
29
    
30
    /* (non-Javadoc)
31
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
32
     */
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
    
37
    /* (non-Javadoc)
38
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
39
     */
40
    public int getType() {
41
        return delegate.getType();
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 9, 2005
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Style - Code Templates
6
 */
7
package org.apache.poi.hssf.record.formula.eval;
8
9
import org.apache.poi.hssf.record.formula.Ptg;
10
import org.apache.poi.hssf.record.formula.ReferencePtg;
11
12
/**
13
 * @author adeshmukh
14
 *
15
 * TODO To change the template for this generated type comment go to
16
 * Window - Preferences - Java - Code Style - Code Templates
17
 */
18
public class Ref2DEval implements RefEval {
19
20
	private ValueEval value;
21
	
22
	private ReferencePtg delegate;
23
	
24
	public Ref2DEval(Ptg ptg, ValueEval value) {
25
		this.value = value;
26
		this.delegate = (ReferencePtg) ptg;
27
	}
28
	
29
	/* (non-Javadoc)
30
	 * @see org.apache.poi.hssf.record.formula.eval.RefEval#getInnerValueEval()
31
	 */
32
	public ValueEval getInnerValueEval() {
33
		return value;
34
	}
35
	
36
	public short getRow() {
37
		return delegate.getRow();
38
	}
39
	
40
	public short getColumn() {
41
		return delegate.getColumn();
42
	}
43
	
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 9, 2005
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Style - Code Templates
6
 */
7
package org.apache.poi.hssf.record.formula.eval;
8
9
import org.apache.poi.hssf.record.formula.Ptg;
10
import org.apache.poi.hssf.record.formula.Ref3DPtg;
11
12
/**
13
 * @author adeshmukh
14
 *
15
 * TODO To change the template for this generated type comment go to
16
 * Window - Preferences - Java - Code Style - Code Templates
17
 */
18
public class Ref3DEval implements RefEval {
19
20
	private ValueEval value;
21
	
22
	private Ref3DPtg delegate;
23
	
24
	public Ref3DEval(Ptg ptg, ValueEval value) {
25
		this.value = value;
26
		this.delegate = (Ref3DPtg) ptg;
27
	}
28
	
29
	/* (non-Javadoc)
30
	 * @see org.apache.poi.hssf.record.formula.eval.RefEval#getInnerValueEval()
31
	 */
32
	public ValueEval getInnerValueEval() {
33
		return value;
34
	}
35
	
36
	public short getRow() {
37
		return delegate.getRow();
38
	}
39
	
40
	public short getColumn() {
41
		return delegate.getColumn();
42
	}
43
	
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java (+29 lines)
Added Link Here
1
/*
2
 * Created on May 9, 2005
3
 *
4
 * 
5
 */
6
package org.apache.poi.hssf.record.formula.eval;
7
8
9
/**
10
 * @author Amol S Deshmukh &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 * RefEval is the super interface for Ref2D and Ref3DEval.
13
 * Basically a RefEval impl should contain reference to
14
 * the original ReferencePtg or Ref3DPtg as well as the
15
 * final "value" resulting from the evaluation of the cell 
16
 * reference. Thus if the HSSFCell has type CELL_TYPE_NUMERIC,
17
 * the contained value object should be of type NumberEval;
18
 * if cell type is CELL_TYPE_STRING, contained value object
19
 * should be of type StringEval 
20
 */
21
public interface RefEval extends ValueEval {
22
23
	public ValueEval getInnerValueEval();
24
	
25
	public short getColumn();
26
	
27
	public short getRow();
28
29
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringEval.java (+29 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.Ptg;
8
import org.apache.poi.hssf.record.formula.StringPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class StringEval implements StringValueEval {
15
16
    private String value;
17
    
18
    public StringEval(Ptg ptg) {
19
        this.value = ((StringPtg) ptg).getValue();
20
    }
21
    
22
    public StringEval(String value) {
23
        this.value = value;
24
    }
25
    
26
    public String getStringValue() {
27
        return value;
28
    }
29
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.java (+15 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
8
/**
9
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
10
 *
11
 */
12
public interface StringValueEval extends ValueEval {
13
14
    public String getStringValue();
15
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java (+82 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.Ptg;
8
import org.apache.poi.hssf.record.formula.SubtractPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class SubtractEval implements OperationEval {
15
16
    private SubtractPtg delegate;
17
    
18
    public SubtractEval(Ptg ptg) {
19
        delegate = (SubtractPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        double d0 = 0;
27
        double d1 = 0;
28
        Eval retval = null;
29
    	
30
        if (operands[0] instanceof NumericValueEval) {
31
    		d0 = ((NumberEval) operands[0]).getNumberValue();
32
    	}
33
    	else if (operands[0] instanceof RefEval) {
34
    	    RefEval re = (RefEval) operands[0];
35
    	    ValueEval ve = (ValueEval) re.getInnerValueEval();
36
        	if (ve instanceof NumericValueEval) {
37
        		d0 = ((NumberEval) ve).getNumberValue();
38
        	}
39
        	else {
40
        	    retval = ErrorEval.ERROR_502;
41
        	}
42
    	}
43
    	else {
44
    	    retval = ErrorEval.ERROR_502;
45
    	}
46
    	
47
        if (operands[1] instanceof NumericValueEval) {
48
    		d1 = ((NumberEval) operands[1]).getNumberValue();
49
    	}
50
    	else if (operands[1] instanceof RefEval) {
51
    	    RefEval re = (RefEval) operands[1];
52
    	    ValueEval ve = (ValueEval) re.getInnerValueEval();
53
        	if (ve instanceof NumericValueEval) {
54
        		d1 = ((NumberEval) ve).getNumberValue();
55
        	}
56
        	else {
57
        	    retval = ErrorEval.ERROR_502;
58
        	}
59
    	}
60
    	else {
61
    	    retval = ErrorEval.ERROR_502;
62
    	}
63
    	
64
    	if (retval == null) 
65
    	    retval = new NumberEval(d0-d1);
66
    	return retval;
67
    }
68
    
69
    /* (non-Javadoc)
70
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
71
     */
72
    public int getNumberOfOperands() {
73
        return delegate.getNumberOfOperands();
74
    }
75
    
76
    /* (non-Javadoc)
77
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
78
     */
79
    public int getType() {
80
        return delegate.getType();
81
    }
82
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java (+65 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.Ptg;
8
import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class UnaryMinusEval implements OperationEval {
15
16
    private UnaryMinusPtg delegate;
17
    
18
    public UnaryMinusEval(Ptg ptg) {
19
        this.delegate = (UnaryMinusPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        ValueEval retval = null;
27
        double d = 0;
28
        if (operands[0] instanceof NumericValueEval) {
29
            NumericValueEval nve = (NumericValueEval) operands[0];
30
            d = nve.getNumberValue();
31
        }
32
        else if (operands[0] instanceof RefEval) {
33
            RefEval re = (RefEval) operands[0];
34
            ValueEval ve = re.getInnerValueEval();
35
            if (ve instanceof NumericValueEval) {
36
                NumericValueEval nve = (NumericValueEval) ve;
37
                d = nve.getNumberValue();
38
            }
39
        }
40
        else {
41
            retval = ErrorEval.INVALID_VALUE;
42
        }
43
        
44
        if (retval == null) {
45
            retval = new NumberEval(-d);
46
        }
47
        
48
        return retval;
49
    }
50
    
51
    /* (non-Javadoc)
52
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
53
     */
54
    public int getNumberOfOperands() {
55
        return delegate.getNumberOfOperands();
56
    }
57
    
58
    /* (non-Javadoc)
59
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
60
     */
61
    public int getType() {
62
        return delegate.getType();
63
    }
64
65
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java (+43 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
import org.apache.poi.hssf.record.formula.Ptg;
8
import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class UnaryPlusEval implements OperationEval {
15
16
    private UnaryPlusPtg delegate;
17
    
18
    public UnaryPlusEval(Ptg ptg) {
19
        this.delegate = (UnaryPlusPtg) ptg;
20
    }
21
    
22
    /* (non-Javadoc)
23
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
24
     */
25
    public Eval evaluate(Eval[] operands) {
26
        return operands[0];
27
    }
28
    
29
    /* (non-Javadoc)
30
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getNumberOfOperands()
31
     */
32
    public int getNumberOfOperands() {
33
        return delegate.getNumberOfOperands();
34
    }
35
    
36
    /* (non-Javadoc)
37
     * @see org.apache.poi.hssf.record.formula.eval.OperationEval#getType()
38
     */
39
    public int getType() {
40
        return delegate.getType();
41
    }
42
43
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ValueEval.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 8, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.eval;
6
7
/**
8
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
9
 *
10
 */
11
public interface ValueEval extends Eval {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java (+56 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
16
 *
17
 */
18
public class Abs extends DefaultFunctionImpl {
19
20
    
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		double d = 0;
26
		ValueEval retval = null;
27
		if (operands.length == 1) {
28
			if (operands[0] !=null && operands[0] instanceof NumericValueEval) {
29
			    d = Math.abs(((NumericValueEval) operands[0]).getNumberValue());
30
			}
31
			else if (operands[0] instanceof AreaEval) {
32
			    AreaEval ae = (AreaEval) operands[0];
33
			    ValueEval v = ae.getValues()[0];
34
			    if (v != null && v instanceof NumericValueEval) {
35
			        d = Math.abs(((NumericValueEval) v).getNumberValue());
36
			    }
37
			}
38
			else if (operands[0] instanceof ErrorEval) {
39
			    ErrorEval e = (ErrorEval) operands[0];
40
			    retval = e;
41
			}
42
			if (retval != null)
43
			    retval = new NumberEval(d);
44
		}
45
		else {
46
		    retval = ErrorEval.ERROR_508;
47
		}
48
		if (retval != null) {
49
		    retval = (Double.isNaN(d)) 
50
		    		? (ValueEval) ErrorEval.ERROR_502 
51
		            : new NumberEval(d);
52
		}
53
		return retval;
54
	}
55
56
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java (+22 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
9
/**
10
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 */
13
public class Atan extends DefaultFunctionImpl {
14
15
    /* (non-Javadoc)
16
     * @see org.apache.poi.hssf.record.formula.functions.DefaultFunctionImplEval#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[])
17
     */
18
    public Eval evaluate(Eval[] operands) {
19
        return super.evaluate(operands);
20
    }
21
    
22
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java (+75 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Average extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		double d = 0;
26
		int count = 0;
27
		ValueEval retval = null;
28
		for (int i=0, iSize=operands.length; i<iSize; i++) {
29
		    if (operands[i] == null)
30
		         continue;
31
			if (operands[i] instanceof AreaEval) {
32
				AreaEval ap = (AreaEval) operands[i];
33
				Object[] values = ap.getValues();
34
				for (int j=0, jSize=values.length; j<jSize; j++) {
35
				    if (values[j]==null) 
36
				        continue;
37
					if (values[j] instanceof NumericValueEval) { 
38
						d += ((NumericValueEval) values[j]).getNumberValue();
39
						count++;
40
					}
41
					else if (values[j] instanceof RefEval) {
42
					    RefEval re = (RefEval) values[j];
43
					    ValueEval ve = re.getInnerValueEval();
44
						if (ve!=null && ve instanceof NumericValueEval) { 
45
							d += ((NumericValueEval) ve).getNumberValue();
46
							count++;
47
						}
48
					}
49
				}
50
			}
51
			else if (operands[i] instanceof NumericValueEval) {
52
				NumericValueEval np = (NumericValueEval) operands[i];
53
				d += np.getNumberValue();
54
				count++;
55
			}
56
			else if (operands[i] instanceof RefEval) {
57
			    RefEval re = (RefEval) operands[i];
58
			    ValueEval ve = re.getInnerValueEval();
59
			    if (ve instanceof NumericValueEval) {
60
			        NumericValueEval ne = (NumericValueEval) ve;
61
			        d += ne.getNumberValue();
62
			        count++;
63
			    }
64
			}
65
		}
66
67
		if (retval == null) {
68
		    retval = (Double.isNaN(d)) 
69
		    		? (ValueEval) ErrorEval.ERROR_502 
70
		            : new NumberEval(d/count);
71
		}
72
		return retval;
73
	}
74
75
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java (+33 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.RefEval;
11
12
/**
13
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
14
 *
15
 */
16
public class Column extends DefaultFunctionImpl {
17
18
	/* (non-Javadoc)
19
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
20
	 */
21
	public Eval evaluate(Eval[] operands) {
22
		Eval retval = null;
23
		if (operands[0] instanceof RefEval) {
24
			RefEval rp = (RefEval) operands[0];
25
			retval = new NumberEval(rp.getColumn()+1);
26
		}
27
		else {
28
			retval = ErrorEval.ERROR_504;
29
		}
30
		return retval;
31
	}
32
33
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java (+55 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Cos extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		ValueEval retval = null;
26
		double d = 0;
27
		if (operands.length == 1) {
28
			if (operands[0] instanceof NumericValueEval) {
29
			    NumericValueEval np = (NumericValueEval) operands[0];
30
				d = Math.cos(np.getNumberValue());
31
			}
32
			else if (operands[0] instanceof RefEval) {
33
			    RefEval re = (RefEval) operands[0];
34
			    ValueEval ve = re.getInnerValueEval();
35
			    if (ve!=null && ve instanceof NumericValueEval) {
36
			        NumericValueEval np = (NumericValueEval) ve;
37
					d = Math.cos(np.getNumberValue());
38
			    }
39
			}
40
			else if (operands[0] instanceof AreaEval) {
41
				retval = ErrorEval.INVALID_VALUE;
42
			}
43
			else {
44
				retval = ErrorEval.ERROR_502; 
45
			}
46
		}
47
		else {
48
			retval = ErrorEval.ERROR_508;
49
		}
50
		if (retval == null)
51
		    retval = new NumberEval(d);
52
		return retval;
53
	}
54
55
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java (+63 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
11
import org.apache.poi.hssf.record.formula.eval.RefEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
16
 *
17
 */
18
public class Count extends DefaultFunctionImpl {
19
20
	/* (non-Javadoc)
21
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
22
	 */
23
	public Eval evaluate(Eval[] operands) {
24
		int count = 0;
25
		for (int i=0, iSize=operands.length; i<iSize; i++) {
26
			if (operands[i] instanceof AreaEval) {
27
				AreaEval ap = (AreaEval) operands[i];
28
				ValueEval[] values = ap.getValues();
29
				for (int j=0, jSize=values.length; j<jSize; j++) {
30
				    if (values[j]==null)
31
				        continue;
32
					if ((values[j] instanceof NumericValueEval)) {
33
					    count++;
34
					}
35
					else if (values[j] instanceof RefEval){
36
					    RefEval re = (RefEval) values[j];
37
					    ValueEval ve = re.getInnerValueEval();
38
						if ((values[j] instanceof NumericValueEval)) {
39
						    count++;
40
						}
41
					}
42
				}
43
			}
44
			else if (operands[i] instanceof NumericValueEval) {
45
			    count++;
46
			}
47
			else if (operands[i] instanceof RefEval){
48
			    RefEval re = (RefEval) operands[i];
49
			    ValueEval ve = re.getInnerValueEval();
50
				if ((operands[i] instanceof NumericValueEval)) {
51
				    count++;
52
				}
53
			}
54
		}
55
56
		// TODO: --Note-- 
57
		// Count behaves (slightly) differently in Oo and Excel.
58
		// Oo counts boolean values (whether true or false), Excel
59
		// ignores booleans. Strings are ignored by both Oo and Excel.
60
		return new NumberEval(count);
61
	}
62
63
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.java (+21 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
10
/**
11
 * 
12
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
13
 */
14
public abstract class DefaultFunctionImpl implements Function {
15
16
	public Eval evaluate(Eval[] operands) {
17
		return ErrorEval.FUNCTION_NOT_IMPLEMENTED;
18
	}
19
	
20
21
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.java (+77 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.StringEval;
14
import org.apache.poi.hssf.record.formula.eval.ValueEval;
15
16
/**
17
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
18
 * 
19
 */
20
public class Dollar extends DefaultFunctionImpl {
21
    //private static final DecimalFormat DOLLAR_FORMAT = new DecimalFormat("$#,##0.0#");
22
23
	/* (non-Javadoc)
24
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
25
	 */
26
	public Eval evaluate(Eval[] operands) {
27
		double d = 0;
28
		ValueEval retval = null;
29
		if (operands[0] != null) {
30
			if (operands[0] instanceof NumericValueEval) {
31
				NumericValueEval np = (NumericValueEval) operands[0];
32
				d = np.getNumberValue();
33
			}
34
			else if (operands[0] instanceof RefEval) {
35
				RefEval re = (RefEval) operands[0];
36
				ValueEval ve = re.getInnerValueEval();
37
				if (ve!=null && ve instanceof NumericValueEval) {
38
					NumericValueEval np = (NumericValueEval) ve;
39
					d = np.getNumberValue();
40
				}
41
			}
42
			else if (operands[0] instanceof AreaEval) {
43
				 retval = ErrorEval.INVALID_VALUE;
44
			}
45
			else if (operands[0] instanceof StringEval) {
46
				StringEval se = (StringEval) operands[0];
47
				String s = se.getStringValue();
48
				try {
49
					d = Double.parseDouble(s);
50
				} catch (NumberFormatException nfe) {
51
					retval = ErrorEval.INVALID_VALUE;
52
				}
53
			}
54
			else {
55
				d=Math.tan(0); 
56
			}
57
		}
58
		if (retval == null) {
59
		    retval = new NumberEval(d);
60
		}
61
		
62
		// TODO: this is a little tricky function to implement:
63
		// because while display value is a dollar format string, 
64
		// the type is treated as numeric when used in formulas.
65
		// For now, the returned type is kept "NumberEval"
66
		// since it will cause it to work better with other
67
		// formulas.
68
		// MoreImportantly, OpenOffice and Excel differ in their
69
		// implementation of DOLLAR, Oo treats DOLLAr eval as 
70
		// String, Excel treats it as Number - This class
71
		// treats it as a number but/hence does not do the
72
		// formatting that DOLLAR should: In programs, this
73
		//  impl should be more useful.
74
		return retval;
75
	}
76
77
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java (+36 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 */
4
package org.apache.poi.hssf.record.formula.functions;
5
6
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
import org.apache.poi.hssf.record.formula.eval.NumberEval;
9
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
10
import org.apache.poi.hssf.record.formula.eval.ValueEval;
11
/**
12
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
13
 *
14
 */
15
public class Exp extends DefaultFunctionImpl {
16
17
	/* (non-Javadoc)
18
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
19
	 */
20
	public Eval evaluate(Eval[] operands) {
21
		double d = 0;
22
		ValueEval retval = null;
23
		if (operands!=null) {
24
			if (operands[0] instanceof NumericValueEval) {
25
			    NumericValueEval np = (NumericValueEval) operands[0];
26
				d = Math.pow(Math.E, np.getNumberValue());
27
			}
28
			else {
29
				retval = ErrorEval.INVALID_VALUE;
30
			}
31
		}
32
		if (retval == null) 
33
		    retval = new NumberEval(d);
34
		return retval;
35
	}
36
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Fixed.java (+127 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
import org.apache.poi.hssf.record.formula.eval.NumberEval;
9
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
10
11
/**
12
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
13
 * <pre>
14
 * Function spec:
15
 * 1. numargs= 1-3
16
 * 2. args= 1: number; 2: decimal places; 3: show thousands separator?
17
 * </pre>
18
 */
19
public class Fixed extends DefaultFunctionImpl {
20
    
21
    private static final boolean DEFAULT_SHOW_THOUSANDS_SEP = true;
22
    private static final int DEFAULT_NUM_DIGITS_AFTER_DECIMALS = 2;
23
24
	/* (non-Javadoc)
25
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
26
	 */
27
	public Eval evaluate(Eval[] operands) {
28
		double d;
29
		boolean showThousandsSep = DEFAULT_SHOW_THOUSANDS_SEP;
30
		int numdecimals=DEFAULT_NUM_DIGITS_AFTER_DECIMALS;
31
		
32
		switch (operands.length) {
33
		case 3:
34
		    if (operands[2] instanceof NumericValueEval) {
35
		        NumericValueEval np = (NumericValueEval) operands[2];
36
		        showThousandsSep = np.getNumberValue() != 0;
37
		    }
38
		    else {
39
		        showThousandsSep = false;
40
		    }
41
		case 2:
42
		    if (operands[1] instanceof NumericValueEval) {
43
		        NumericValueEval np = (NumericValueEval) operands[1];
44
		        numdecimals = (int) np.getNumberValue();
45
		    }
46
		    else {
47
		        numdecimals = 0;
48
		    }
49
		default: // 1 operand
50
		    if (operands[0] instanceof NumericValueEval) {
51
		        NumericValueEval np = (NumericValueEval) operands[0];
52
		        d = np.getNumberValue();
53
		    }
54
		    else {
55
		        d = 0;
56
		    }
57
		}
58
		
59
		// String str = formatDecimal(d, numdecimals, showThousandsSep);
60
		// return new StringPtg(str);
61
		// TODO: this is a little tricky function to implement:
62
		// because while display value is a fixed format string, 
63
		// the type is treated as numeric when used in formulas.
64
		// For now, the returned type is kept "NumberEval"
65
		// since it will cause it to work better with other
66
		// formulas.
67
		// MoreImportantly, OpenOffice and Excel differ in their
68
		// implementation of FIXED, Oo treats FIXED eval as 
69
		// String, Excel treats it as Number - This class
70
		// treats it as a number but/hence does not do the
71
		// formatting that FIXED should: In programs, this
72
		//  impl should be more useful. 
73
		// To switch to strictly Oo implementation, uncomment the 
74
		// 2 lines above this_TODO and remove the lines below 
75
		// this_TODO.
76
		
77
		return new NumberEval(d);
78
	}
79
	
80
	/**
81
	 * return string representation of double with specified formatting options
82
	 * @param d
83
	 * @param numdecimals
84
	 * @param showT
85
	 * @return
86
	 */
87
	static final String formatDecimal(double d, int numdecimals, boolean showT) {
88
	    StringBuffer sb = new StringBuffer(50); // 50 => optimze for speed for common values
89
	    long integral = (long) d;
90
	    double fraction = d-integral;
91
92
	    if (showT) {
93
	        String sintegral = String.valueOf(integral);
94
	        for (int i=sintegral.length()-1, j=1; i>=0; i--, j++) {
95
	            char c = sintegral.charAt(i);
96
	            sb.append(c);
97
	            if (j%3==0 && i!=0) sb.append(',');
98
	        }
99
	        sb.reverse();
100
	    }
101
	    else {
102
	        sb.append(integral);
103
	    }
104
	    sb.append(ensureLength(fraction, numdecimals));
105
	    return sb.toString();
106
	}
107
	
108
	// TODO: optimize this function
109
	/**
110
	 * returns a truncated or padded String representation of
111
	 * double fraction. double fraction MUST be >0 && <1.
112
	 */
113
	static final String ensureLength(double fraction, int numdecimals) {
114
	    StringBuffer sb = new StringBuffer();
115
	    if (numdecimals != 0) {
116
		    int ifraction = (int) (fraction * Math.pow(10, numdecimals));
117
		    String sfraction = String.valueOf(ifraction);
118
		    
119
		    sb.append('.').append(ifraction);
120
		    for (int i=numdecimals-sfraction.length(); i>0; i--) {
121
		        sb.append('0');
122
		    }
123
	    }
124
	    return sb.toString();
125
	}
126
127
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Function.java (+18 lines)
Added Link Here
1
/*
2
 * Created on May 9, 2005
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Style - Code Templates
6
 */
7
package org.apache.poi.hssf.record.formula.functions;
8
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
11
/**
12
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
13
 *
14
 */
15
public interface Function {
16
17
    public Eval evaluate(Eval[] operands);
18
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Int.java (+52 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
11
import org.apache.poi.hssf.record.formula.eval.RefEval;
12
import org.apache.poi.hssf.record.formula.eval.StringEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Int extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		double d = 0;
26
		ValueEval retval = null;
27
		if (operands.length == 1) {
28
			if (operands[0] instanceof NumericValueEval) {
29
				NumericValueEval ne = (NumericValueEval) operands[0];
30
				d = ne.getNumberValue();
31
			}
32
			else if (operands[0] instanceof RefEval) {
33
			    
34
			}
35
			else if (operands[0] instanceof StringEval) {
36
				retval = ErrorEval.ERROR_502;
37
			}
38
		}
39
		else if (operands.length > 1) {
40
		    retval = ErrorEval.ERROR_508;
41
		}
42
		else {
43
		    retval = ErrorEval.ERROR_511;
44
		}
45
		if (retval == null) {
46
		    retval = new NumberEval(d);
47
		}
48
		
49
		return retval;
50
	}
51
52
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsError.java (+26 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.BoolEval;
9
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
10
import org.apache.poi.hssf.record.formula.eval.Eval;
11
12
/**
13
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
14
 *
15
 */
16
public class IsError extends DefaultFunctionImpl {
17
18
	/* (non-Javadoc)
19
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
20
	 */
21
	public Eval evaluate(Eval[] operands) {
22
	    boolean b = (operands[0] instanceof ErrorEval) || (operands[0] instanceof AreaEval);
23
		return new BoolEval(b);
24
	}
25
26
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/IsNa.java (+25 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Style - Code Templates
6
 */
7
package org.apache.poi.hssf.record.formula.functions;
8
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
11
/**
12
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
13
 *
14
 * Window - Preferences - Java - Code Style - Code Templates
15
 */
16
public class IsNa extends DefaultFunctionImpl {
17
18
	/* (non-Javadoc)
19
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
20
	 */
21
	public Eval evaluate(Eval[] operands) {
22
		return super.evaluate(operands);
23
	}
24
25
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ln.java (+61 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Ln extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		double d = 0;
26
		ValueEval retval = null;
27
		switch (operands.length) {
28
		case 1:
29
			if (operands[0] instanceof NumericValueEval) {
30
			    NumericValueEval ne = (NumericValueEval) operands[0];
31
				d = Math.log(ne.getNumberValue());
32
			}
33
			else if (operands[0] instanceof RefEval) {
34
			    RefEval re = (RefEval) operands[0];
35
			    ValueEval ve = re.getInnerValueEval();
36
			    if (ve instanceof NumericValueEval) {
37
				    NumericValueEval ne = (NumericValueEval) ve;
38
					d = Math.log(ne.getNumberValue());
39
			    }
40
			}
41
			else if (operands[0] instanceof AreaEval) {
42
				 retval = ErrorEval.INVALID_VALUE;
43
			}
44
			else {
45
			    retval = ErrorEval.ERROR_502; 
46
			}
47
		    break;
48
		case 0:
49
		    retval = ErrorEval.ERROR_502;
50
		    break;
51
		default:
52
		    retval = ErrorEval.ERROR_508;
53
		}
54
		if (retval == null) {
55
		    retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_503 : new NumberEval(d);
56
		}
57
		
58
		return retval;
59
	}
60
61
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Log10.java (+63 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Log10 extends DefaultFunctionImpl {
20
	private static final double LOG_10_TO_BASE_e = Math.log(10);
21
	
22
23
	/* (non-Javadoc)
24
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
25
	 */
26
	public Eval evaluate(Eval[] operands) {
27
		double d = 0;
28
		ValueEval retval = null;
29
		switch (operands.length) {
30
		case 1:
31
			if (operands[0] instanceof NumericValueEval) {
32
			    NumericValueEval ne = (NumericValueEval) operands[0];
33
				d = Math.log(ne.getNumberValue());
34
			}
35
			else if (operands[0] instanceof RefEval) {
36
			    RefEval re = (RefEval) operands[0];
37
			    ValueEval ve = re.getInnerValueEval();
38
			    if (ve instanceof NumericValueEval) {
39
				    NumericValueEval ne = (NumericValueEval) operands[0];
40
					d = Math.log(ne.getNumberValue());
41
			    }
42
			}
43
			else if (operands[0] instanceof AreaEval) {
44
				 retval = ErrorEval.INVALID_VALUE;
45
			}
46
			else {
47
			    retval = ErrorEval.ERROR_502; 
48
			}
49
		    break;
50
		case 0:
51
		    retval = ErrorEval.ERROR_502;
52
		    break;
53
		default:
54
		    retval = ErrorEval.ERROR_508;
55
		}
56
		if (retval != null) {
57
		    retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_503 : new NumberEval(d/LOG_10_TO_BASE_e);
58
		}
59
		
60
		return retval;
61
	}
62
63
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Max.java (+54 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
11
import org.apache.poi.hssf.record.formula.eval.RefEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
16
 *
17
 */
18
public class Max extends DefaultFunctionImpl {
19
20
	/* (non-Javadoc)
21
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
22
	 */
23
	public Eval evaluate(Eval[] operands) {
24
		double d = 0;
25
		for (int i=0, iSize=operands.length; i<iSize; i++) {
26
			if (operands[i] instanceof AreaEval) {
27
			    AreaEval ap = (AreaEval) operands[i];
28
				ValueEval[] values = ap.getValues();
29
				for (int j=0, jSize=values.length; j<jSize; j++) {
30
				    if (values[j]!=null) {
31
						if (values[j] instanceof NumericValueEval) {
32
							d = Math.max(((NumericValueEval) values[j]).getNumberValue(), d);
33
						}
34
						else if (values[j] instanceof RefEval)	{
35
						    ValueEval ve = ((RefEval) values[j]).getInnerValueEval();
36
						    if (ve!=null)
37
						        d = Math.max(((NumericValueEval) ve).getNumberValue(), d);
38
						}
39
				    }
40
				}
41
			}
42
			else if (operands[i] instanceof NumericValueEval) {
43
				d = Math.max(((NumericValueEval) operands[i]).getNumberValue(), d);
44
			}
45
			else if (operands[i] instanceof RefEval)	{
46
			    ValueEval ve = ((RefEval) operands[i]).getInnerValueEval();
47
			    if (ve!=null)
48
			        d = Math.max(((NumericValueEval) ve).getNumberValue(), d);
49
			}
50
		}
51
		
52
		return new NumberEval(d);
53
	}
54
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Min.java (+54 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
11
import org.apache.poi.hssf.record.formula.eval.RefEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
16
 *
17
 */
18
public class Min extends DefaultFunctionImpl {
19
20
	/* (non-Javadoc)
21
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
22
	 */
23
	public Eval evaluate(Eval[] operands) {
24
		double d = 0;
25
		for (int i=0, iSize=operands.length; i<iSize; i++) {
26
			if (operands[i] instanceof AreaEval) {
27
			    AreaEval ap = (AreaEval) operands[i];
28
				ValueEval[] values = ap.getValues();
29
				for (int j=0, jSize=values.length; j<jSize; j++) {
30
				    if (values[j]!=null) {
31
						if (values[j] instanceof NumericValueEval) {
32
							d = Math.min(((NumericValueEval) values[j]).getNumberValue(), d);
33
						}
34
						else if (values[j] instanceof RefEval)	{
35
						    ValueEval ve = ((RefEval) values[j]).getInnerValueEval();
36
						    if (ve!=null)
37
						        d = Math.min(((NumericValueEval) ve).getNumberValue(), d);
38
						}
39
				    }
40
				}
41
			}
42
			else if (operands[i] instanceof NumericValueEval) {
43
				d = Math.min(((NumericValueEval) operands[i]).getNumberValue(), d);
44
			}
45
			else if (operands[i] instanceof RefEval)	{
46
			    ValueEval ve = ((RefEval) operands[i]).getInnerValueEval();
47
			    if (ve!=null)
48
			        d = Math.min(((NumericValueEval) ve).getNumberValue(), d);
49
			}
50
		}
51
		
52
		return new NumberEval(d);
53
	}
54
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Na.java (+24 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
9
/**
10
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 */
13
14
public class Na extends DefaultFunctionImpl {
15
16
    
17
	/* (non-Javadoc)
18
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
19
	 */
20
	public Eval evaluate(Eval[] operands) {
21
	    return super.evaluate(operands);
22
	}
23
24
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Npv.java (+91 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
20
public class Npv extends DefaultFunctionImpl {
21
22
	/* (non-Javadoc)
23
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Eval[])
24
	 */
25
	public Eval evaluate(Eval[] operands) {
26
		double d = 0;
27
		double rate = 0;
28
		ValueEval retval = null;
29
		
30
		if (operands[0] instanceof NumericValueEval) {
31
		    NumericValueEval np = (NumericValueEval) operands[0];
32
		    rate = np.getNumberValue();
33
		}
34
		else if (operands[0] instanceof RefEval) {
35
		    RefEval re = (RefEval) operands[0];
36
		    ValueEval ve = re.getInnerValueEval();
37
		    if (ve instanceof NumericValueEval) {
38
			    NumericValueEval np = (NumericValueEval) ve;
39
			    rate = np.getNumberValue();
40
			}				
41
		}
42
		else {
43
		    retval = ErrorEval.ERROR_503;
44
		}
45
		double denomVal = rate+1;
46
		
47
		if (retval == null) {
48
			for (int i=1, k=1, iSize=operands.length; i<iSize; i++) {
49
				if (operands[i] instanceof AreaEval) {
50
					AreaEval ap = (AreaEval) operands[i];
51
					Object[] values = ap.getValues();
52
					for (int j=0, jSize=values.length; j<jSize; j++) {
53
						if (values[j]==null || !(values[j] instanceof Number)) 
54
							continue;
55
						double value = ((Number) values[j]).doubleValue();
56
						d += value / denomVal;
57
						denomVal = (rate+1) * denomVal;
58
					}
59
				}
60
				else if (operands[i] instanceof NumericValueEval) {
61
					NumberEval np = (NumberEval) operands[i];
62
					double value = np.getNumberValue();
63
					d += value / denomVal;
64
					denomVal = (rate+1) * denomVal;
65
				}
66
				else if (operands[i] instanceof RefEval) {
67
				    RefEval re = (RefEval) operands[i];
68
				    ValueEval ve = re.getInnerValueEval();
69
				    if (ve instanceof NumericValueEval) {
70
						NumberEval np = (NumberEval) ve;
71
						double value = np.getNumberValue();
72
						d += value / denomVal;
73
						denomVal = (rate+1) * denomVal;
74
					}				
75
				}
76
				else {
77
				    retval = ErrorEval.ERROR_503;
78
				}
79
			}
80
		}
81
		else {
82
		    retval = ErrorEval.ERROR_503;
83
		}
84
		
85
		if (retval == null)
86
		    retval = new NumberEval(d);
87
		
88
		return retval;
89
	}
90
91
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pi.java (+25 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
import org.apache.poi.hssf.record.formula.eval.NumberEval;
9
10
/**
11
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
12
 *
13
 */
14
public class Pi extends DefaultFunctionImpl {
15
16
    private static final NumberEval PI_EVAL = new NumberEval(Math.PI);
17
    
18
	/* (non-Javadoc)
19
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
20
	 */
21
	public Eval evaluate(Eval[] operands) {
22
		return PI_EVAL;
23
	}
24
25
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Round.java (+74 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
11
import org.apache.poi.hssf.record.formula.eval.RefEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
16
 *
17
 */
18
public class Round extends DefaultFunctionImpl {
19
20
    private static final short DEFAULT_ACCURACY = 0;
21
    
22
	/* (non-Javadoc)
23
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
24
	 */
25
	public Eval evaluate(Eval[] operands) {
26
		short accuracy = DEFAULT_ACCURACY;
27
		double d = 0;
28
		ValueEval retval = null;
29
		if (operands[0] instanceof NumericValueEval) {
30
		    NumericValueEval bp = (NumericValueEval) operands[0];
31
		    d = bp.getNumberValue();
32
		}
33
		else if (operands[0] instanceof RefEval) {
34
		    RefEval re = (RefEval) operands[0];
35
		    ValueEval ve = re.getInnerValueEval();
36
			if (ve instanceof NumericValueEval) {
37
			    NumericValueEval n = (NumericValueEval) ve;
38
			    d = n.getNumberValue();
39
			}
40
		}
41
		else {
42
		    retval = ErrorEval.ERROR_502;
43
		}
44
		
45
		if (operands.length == 2) {
46
			if (operands[1] instanceof NumericValueEval) {
47
			    NumericValueEval bp = (NumericValueEval) operands[0];
48
			    accuracy = (short) bp.getNumberValue();
49
			}
50
			else if (operands[1] instanceof RefEval) {
51
			    RefEval re = (RefEval) operands[1];
52
			    ValueEval ve = re.getInnerValueEval();
53
				if (ve instanceof NumericValueEval) {
54
				    NumericValueEval n = (NumericValueEval) ve;
55
				    accuracy = (short) n.getNumberValue();
56
				}
57
			}
58
			else {
59
			    retval = ErrorEval.ERROR_502;
60
			}
61
		}
62
		else if (operands.length > 2) {
63
		    retval = ErrorEval.ERROR_504;
64
		}
65
		if (retval == null) {
66
			double power = Math.pow(10, accuracy);
67
			d *= power;
68
			d = Math.round(d);
69
			retval = new NumberEval(d/power);
70
		}
71
		return retval;
72
	}
73
74
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Row.java (+33 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
import org.apache.poi.hssf.record.formula.eval.NumberEval;
10
import org.apache.poi.hssf.record.formula.eval.RefEval;
11
12
/**
13
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
14
 *
15
 */
16
public class Row extends DefaultFunctionImpl {
17
18
	/* (non-Javadoc)
19
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
20
	 */
21
	public Eval evaluate(Eval[] operands) {
22
		Eval retval = null;
23
		if (operands[0] instanceof RefEval) {
24
			RefEval rp = (RefEval) operands[0];
25
			retval = new NumberEval(rp.getRow()+1);
26
		}
27
		else {
28
			retval = ErrorEval.ERROR_504;
29
		}
30
		return retval;
31
	}
32
33
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sign.java (+44 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
import org.apache.poi.hssf.record.formula.eval.NumberEval;
9
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
10
import org.apache.poi.hssf.record.formula.eval.ValueEval;
11
12
/**
13
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
14
 *
15
 */
16
public class Sign extends DefaultFunctionImpl {
17
18
    private static final NumberEval NEG_SIGN_EVAL = new NumberEval(-1);
19
    private static final NumberEval POS_SIGN_EVAL = new NumberEval(1);
20
    private static final NumberEval ZERO_SIGN_EVAL = new NumberEval(0);
21
    
22
	/* (non-Javadoc)
23
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
24
	 */
25
	public Eval evaluate(Eval[] operands) {
26
	    double d = 0;
27
	    ValueEval retval = null;
28
	    if (operands[0] instanceof NumericValueEval) {
29
	        NumericValueEval nve = (NumericValueEval) operands[0];
30
	        d = nve.getNumberValue();
31
	    }
32
	    if (d == 0) {
33
	        retval = ZERO_SIGN_EVAL;
34
	    }
35
	    else if (d < 0) {
36
	        retval = NEG_SIGN_EVAL;
37
	    }
38
	    else if (d > 0) {
39
	        retval = POS_SIGN_EVAL;
40
	    }
41
		return retval;
42
	}
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sin.java (+55 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Sin extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		ValueEval retval = null;
26
		double d = 0;
27
		if (operands.length == 1) {
28
			if (operands[0] instanceof NumericValueEval) {
29
			    NumericValueEval np = (NumericValueEval) operands[0];
30
				d = Math.sin(np.getNumberValue());
31
			}
32
			else if (operands[0] instanceof RefEval) {
33
			    RefEval re = (RefEval) operands[0];
34
			    ValueEval ve = re.getInnerValueEval();
35
			    if (ve!=null && ve instanceof NumericValueEval) {
36
			        NumericValueEval np = (NumericValueEval) ve;
37
					d = Math.sin(np.getNumberValue());
38
			    }
39
			}
40
			else if (operands[0] instanceof AreaEval) {
41
				retval = ErrorEval.INVALID_VALUE;
42
			}
43
			else {
44
				retval = ErrorEval.ERROR_502; 
45
			}
46
		}
47
		else {
48
			retval = ErrorEval.ERROR_508;
49
		}
50
		if (retval == null)
51
		    retval = new NumberEval(d);
52
		return retval;
53
	}
54
55
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sqrt.java (+56 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Sqrt extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		ValueEval retval = null;
26
		double d = 0;
27
		if (operands.length == 1) {
28
			if (operands[0] instanceof NumericValueEval) {
29
			    NumericValueEval np = (NumericValueEval) operands[0];
30
				d = Math.sqrt(np.getNumberValue());
31
			}
32
			else if (operands[0] instanceof RefEval) {
33
			    RefEval re = (RefEval) operands[0];
34
			    ValueEval ve = re.getInnerValueEval();
35
			    if (ve!=null && ve instanceof NumericValueEval) {
36
			        NumericValueEval np = (NumericValueEval) ve;
37
					d = Math.sqrt(np.getNumberValue());
38
			    }
39
			}
40
			else if (operands[0] instanceof AreaEval) {
41
				retval = ErrorEval.INVALID_VALUE;
42
			}
43
			else {
44
				retval = ErrorEval.ERROR_502; 
45
			}
46
		}
47
		else {
48
			retval = ErrorEval.ERROR_508;
49
		}
50
		if (retval != null) {
51
		    retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.ERROR_502 : new NumberEval(d);
52
		}
53
		return retval;
54
	}
55
56
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Stdev.java (+79 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
9
/**
10
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 */
13
public class Stdev extends DefaultFunctionImpl {
14
15
	/* (non-Javadoc)
16
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
17
	 */
18
	public Eval evaluate(Eval[] operands) {
19
	    return super.evaluate(operands);
20
//		double mean = 0;
21
//		int count = 0;
22
//		double numerator = 0;
23
//		
24
//		for (int i=0, iSize=operands.length; i<iSize; i++) {
25
//			if (operands[i] instanceof AreaPtg) {
26
//				AreaPtg ap = (AreaPtg) operands[i];
27
//				Object[] values = ap.getValues();
28
//				for (int j=0, jSize=values.length; j<jSize; j++) {
29
//					if (values[j]!=null && !(values[j] instanceof Number)) { 
30
//						mean += ((Number) values[j]).doubleValue();
31
//						count++;
32
//					}
33
//					else if (values[j] instanceof Boolean) {
34
//					    mean += ((Boolean) values[j]).booleanValue() ? 1 : 0;
35
//					    count++;
36
//					}
37
//				}
38
//			}
39
//			else if (operands[i] instanceof IntPtg) {
40
//				IntPtg ip = (IntPtg) operands[i];
41
//				mean += ip.getValue();
42
//				count++;
43
//			}
44
//			else if (operands[i] instanceof NumberPtg) {
45
//				NumberPtg np = (NumberPtg) operands[i];
46
//				mean += np.getValue();
47
//				count++;
48
//			}
49
//		}
50
//		mean /= count;
51
//
52
//		for (int i=0, iSize=operands.length; i<iSize; i++) {
53
//			if (operands[i] instanceof AreaPtg) {
54
//				AreaPtg ap = (AreaPtg) operands[i];
55
//				Object[] values = ap.getValues();
56
//				for (int j=0, jSize=values.length; j<jSize; j++) {
57
//					if (values[j]==null || !(values[j] instanceof Number)) 
58
//						continue;
59
//					double d = (((Number) values[j]).doubleValue() - mean);
60
//					numerator += d*d;
61
//				}
62
//			}
63
//			else if (operands[i] instanceof IntPtg) {
64
//				IntPtg ip = (IntPtg) operands[i];
65
//				double d = (ip.getValue() - mean);
66
//				numerator += d*d;
67
//			}
68
//			else if (operands[i] instanceof NumberPtg) {
69
//				NumberPtg np = (NumberPtg) operands[i];
70
//				double d = (np.getValue() - mean);
71
//				numerator += d*d;
72
//			}
73
//		}
74
//		
75
//		
76
//		return new NumberPtg(Math.sqrt(mean/(count-1)));
77
	}
78
79
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Sum.java (+68 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.AreaEval;
8
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
9
import org.apache.poi.hssf.record.formula.eval.Eval;
10
import org.apache.poi.hssf.record.formula.eval.NumberEval;
11
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
12
import org.apache.poi.hssf.record.formula.eval.RefEval;
13
import org.apache.poi.hssf.record.formula.eval.ValueEval;
14
15
/**
16
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
17
 *
18
 */
19
public class Sum extends DefaultFunctionImpl {
20
21
	/* (non-Javadoc)
22
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
23
	 */
24
	public Eval evaluate(Eval[] operands) {
25
		double d = 0;
26
		ValueEval retval = null;
27
		for (int i=0, iSize=operands.length; i<iSize; i++) {
28
		    if (operands[i] == null)
29
		         continue;
30
			if (operands[i] instanceof AreaEval) {
31
				AreaEval ap = (AreaEval) operands[i];
32
				Object[] values = ap.getValues();
33
				for (int j=0, jSize=values.length; j<jSize; j++) {
34
				    if (values[j]==null) 
35
				        continue;
36
					if (values[j] instanceof NumericValueEval) { 
37
						d += ((NumericValueEval) values[j]).getNumberValue();
38
					}
39
					else if (values[j] instanceof RefEval) {
40
					    RefEval re = (RefEval) values[j];
41
					    ValueEval ve = re.getInnerValueEval();
42
						if (ve!=null && ve instanceof NumericValueEval) { 
43
							d += ((NumericValueEval) ve).getNumberValue();
44
						}
45
					}
46
				}
47
			}
48
			else if (operands[i] instanceof NumericValueEval) {
49
				NumericValueEval np = (NumericValueEval) operands[i];
50
				d += np.getNumberValue();
51
			}
52
			else if (operands[i] instanceof RefEval) {
53
			    RefEval re = (RefEval) operands[i];
54
			    ValueEval ve = re.getInnerValueEval();
55
			    if (ve instanceof NumericValueEval) {
56
			        NumericValueEval ne = (NumericValueEval) ve;
57
			        d += ne.getNumberValue();
58
			    }
59
			}
60
		}
61
62
		if (retval == null) {
63
		    retval = (Double.isNaN(d)) 
64
		    		? (ValueEval) ErrorEval.ERROR_502 
65
		            : new NumberEval(d);
66
		}
67
		return retval;	}
68
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Tan.java (+45 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.Eval;
8
9
/**
10
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
11
 *
12
 */
13
public class Tan extends DefaultFunctionImpl {
14
15
	/* (non-Javadoc)
16
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.Ptg[])
17
	 */
18
	public Eval evaluate(Eval[] operands) {
19
	    return super.evaluate(operands);
20
//		double d;
21
//		if (operands[0] instanceof IntPtg) {
22
//		    IntPtg np = (IntPtg) operands[0];
23
//			d = Math.tan(np.getValue());
24
//		}
25
//		else if (operands[0] instanceof NumberPtg) {
26
//			NumberPtg np = (NumberPtg) operands[0];
27
//			d = Math.tan(np.getValue());
28
//		}
29
//		else if (operands[0] instanceof AreaPtg) {
30
//			d=Double.NaN; // TODO: Fix this: check with excel, Oo does weird things with Area refs 
31
//		}
32
//		else if (operands[0] instanceof BoolPtg) {
33
//			BoolPtg bp = (BoolPtg) operands[0];
34
//			d=bp.getValue() ? Math.tan(1) : Math.tan(0);  
35
//		}
36
//		else if (operands[0] instanceof StringPtg) {
37
//			d=Math.tan(0);  
38
//		}
39
//		else {
40
//			d=Math.tan(0); 
41
//		}
42
//		return new NumberPtg(d);
43
	}
44
45
}
(-)src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (+480 lines)
Added Link Here
1
/*
2
 * Created on May 5, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.usermodel;
6
import java.io.FileInputStream;
7
import java.lang.reflect.Constructor;
8
import java.util.HashMap;
9
import java.util.Map;
10
import java.util.Stack;
11
12
import org.apache.poi.hssf.model.FormulaParser;
13
import org.apache.poi.hssf.record.formula.AddPtg;
14
import org.apache.poi.hssf.record.formula.Area3DPtg;
15
import org.apache.poi.hssf.record.formula.AreaPtg;
16
import org.apache.poi.hssf.record.formula.AttrPtg;
17
import org.apache.poi.hssf.record.formula.BoolPtg;
18
import org.apache.poi.hssf.record.formula.ConcatPtg;
19
import org.apache.poi.hssf.record.formula.ControlPtg;
20
import org.apache.poi.hssf.record.formula.DividePtg;
21
import org.apache.poi.hssf.record.formula.EqualPtg;
22
import org.apache.poi.hssf.record.formula.FuncPtg;
23
import org.apache.poi.hssf.record.formula.FuncVarPtg;
24
import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
25
import org.apache.poi.hssf.record.formula.GreaterThanPtg;
26
import org.apache.poi.hssf.record.formula.IntPtg;
27
import org.apache.poi.hssf.record.formula.LessEqualPtg;
28
import org.apache.poi.hssf.record.formula.LessThanPtg;
29
import org.apache.poi.hssf.record.formula.MemErrPtg;
30
import org.apache.poi.hssf.record.formula.MissingArgPtg;
31
import org.apache.poi.hssf.record.formula.MultiplyPtg;
32
import org.apache.poi.hssf.record.formula.NamePtg;
33
import org.apache.poi.hssf.record.formula.NameXPtg;
34
import org.apache.poi.hssf.record.formula.NotEqualPtg;
35
import org.apache.poi.hssf.record.formula.NumberPtg;
36
import org.apache.poi.hssf.record.formula.OperationPtg;
37
import org.apache.poi.hssf.record.formula.ParenthesisPtg;
38
import org.apache.poi.hssf.record.formula.PowerPtg;
39
import org.apache.poi.hssf.record.formula.Ptg;
40
import org.apache.poi.hssf.record.formula.Ref3DPtg;
41
import org.apache.poi.hssf.record.formula.ReferencePtg;
42
import org.apache.poi.hssf.record.formula.StringPtg;
43
import org.apache.poi.hssf.record.formula.SubtractPtg;
44
import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
45
import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
46
import org.apache.poi.hssf.record.formula.UnionPtg;
47
import org.apache.poi.hssf.record.formula.UnknownPtg;
48
import org.apache.poi.hssf.record.formula.eval.AddEval;
49
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
50
import org.apache.poi.hssf.record.formula.eval.Area3DEval;
51
import org.apache.poi.hssf.record.formula.eval.AreaEval;
52
import org.apache.poi.hssf.record.formula.eval.BoolEval;
53
import org.apache.poi.hssf.record.formula.eval.ConcatEval;
54
import org.apache.poi.hssf.record.formula.eval.DivideEval;
55
import org.apache.poi.hssf.record.formula.eval.EqualEval;
56
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
57
import org.apache.poi.hssf.record.formula.eval.Eval;
58
import org.apache.poi.hssf.record.formula.eval.FuncVarEval;
59
import org.apache.poi.hssf.record.formula.eval.GreaterEqualEval;
60
import org.apache.poi.hssf.record.formula.eval.GreaterThanEval;
61
import org.apache.poi.hssf.record.formula.eval.LessEqualEval;
62
import org.apache.poi.hssf.record.formula.eval.LessThanEval;
63
import org.apache.poi.hssf.record.formula.eval.MultiplyEval;
64
import org.apache.poi.hssf.record.formula.eval.NotEqualEval;
65
import org.apache.poi.hssf.record.formula.eval.NumberEval;
66
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
67
import org.apache.poi.hssf.record.formula.eval.OperationEval;
68
import org.apache.poi.hssf.record.formula.eval.PowerEval;
69
import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
70
import org.apache.poi.hssf.record.formula.eval.Ref3DEval;
71
import org.apache.poi.hssf.record.formula.eval.RefEval;
72
import org.apache.poi.hssf.record.formula.eval.StringEval;
73
import org.apache.poi.hssf.record.formula.eval.StringValueEval;
74
import org.apache.poi.hssf.record.formula.eval.SubtractEval;
75
import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
76
import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
77
import org.apache.poi.hssf.record.formula.eval.ValueEval;
78
79
/**
80
 * @author amolweb &lt; amolweb at ya hoo dot com &gt;
81
 *
82
 * Limitations:
83
 * Unfortunately, cyclic references will cause stackoverflow exception
84
 */
85
public class HSSFFormulaEvaluator {
86
    
87
    // params to lookup the right constructor using reflection
88
    private static final Class[] OPERATION_CONTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class};
89
    private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class};
90
    private static final Class[] AREA_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval[].class};
91
    private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval[].class};
92
    private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval.class};
93
    private static final Class[] REF3D_CONSTRUCTOR_CLASS_ARRAY = new Class[]{Ptg.class, ValueEval.class};
94
    
95
    // Maps for mapping *Eval to *Ptg
96
    private static final Map VALUE_EVALS_MAP = new HashMap();
97
    private static final Map OPERATION_EVALS_MAP = new HashMap();    
98
    
99
    
100
    /*
101
     * If you dont like this map, join the club :)
102
     * I did this becoz it was desired to keep the FormulaEvaluator
103
     * separate from FormulaParser and related classes in the CVS-HEAD.
104
     * So now we need some mapping between the Ptg tokens that
105
     * the FormulaParser returns and the *Eval classes taht
106
     * are used by the FormulaEvaluator - hence the following :)
107
     */
108
static {
109
    VALUE_EVALS_MAP.put(BoolPtg.class, BoolEval.class);
110
    VALUE_EVALS_MAP.put(IntPtg.class, NumberEval.class);
111
    VALUE_EVALS_MAP.put(NumberPtg.class, NumberEval.class);
112
    VALUE_EVALS_MAP.put(StringPtg.class, StringEval.class);
113
    
114
    OPERATION_EVALS_MAP.put(AddPtg.class, AddEval.class);
115
    OPERATION_EVALS_MAP.put(ConcatPtg.class, ConcatEval.class);
116
    OPERATION_EVALS_MAP.put(DividePtg.class, DivideEval.class);
117
    OPERATION_EVALS_MAP.put(EqualPtg.class, EqualEval.class);
118
    //OPERATION_EVALS_MAP.put(ExpPtg.class, ExpEval.class); // TODO: check this
119
    OPERATION_EVALS_MAP.put(FuncPtg.class, FuncVarEval.class); // TODO: check this
120
    OPERATION_EVALS_MAP.put(FuncVarPtg.class, FuncVarEval.class);
121
    OPERATION_EVALS_MAP.put(GreaterEqualPtg.class, GreaterEqualEval.class);
122
    OPERATION_EVALS_MAP.put(GreaterThanPtg.class, GreaterThanEval.class);
123
    OPERATION_EVALS_MAP.put(LessEqualPtg.class, LessEqualEval.class);
124
    OPERATION_EVALS_MAP.put(LessThanPtg.class, LessThanEval.class);
125
    OPERATION_EVALS_MAP.put(MultiplyPtg.class, MultiplyEval.class);
126
    OPERATION_EVALS_MAP.put(NotEqualPtg.class, NotEqualEval.class);
127
    OPERATION_EVALS_MAP.put(PowerPtg.class, PowerEval.class);
128
    OPERATION_EVALS_MAP.put(SubtractPtg.class, SubtractEval.class);
129
    OPERATION_EVALS_MAP.put(UnaryMinusPtg.class, UnaryMinusEval.class);
130
    OPERATION_EVALS_MAP.put(UnaryPlusPtg.class, UnaryPlusEval.class);
131
132
133
}
134
    
135
	
136
    /**
137
     * debug method
138
     * @param formula
139
     * @param sheet
140
     * @param workbook
141
     */
142
	static void inspectPtgs(String formula, HSSFSheet sheet, HSSFWorkbook workbook) {
143
		FormulaParser fp = new FormulaParser(formula, workbook.getWorkbook());
144
		fp.parse();
145
		Ptg[] ptgs = fp.getRPNPtg();
146
    	System.out.println("<ptg-group>");
147
    	for (int i=0, iSize=ptgs.length; i<iSize; i++) {
148
    		System.out.println("<ptg>");
149
    		System.out.println(ptgs[i]);
150
    		if (ptgs[i] instanceof OperationPtg) {
151
    			System.out.println("numoperands: " + ((OperationPtg) ptgs[i]).getNumberOfOperands());
152
    		}
153
    		System.out.println("</ptg>");
154
		}
155
	}
156
	
157
	/**
158
	 * returns the string value resulting from teh evaluation of the formula
159
	 * @param formula
160
	 * @param sheet
161
	 * @param workbook
162
	 * @return
163
	 */
164
	public static String evaluateToString(String formula, HSSFSheet sheet, HSSFWorkbook workbook) {
165
    	String retval = null;
166
    	Eval value = evaluate(formula, sheet, workbook);
167
    	if (value instanceof NumericValueEval) {
168
    	    NumericValueEval ne = (NumericValueEval) value;
169
    		retval = String.valueOf(ne.getNumberValue());
170
    	}
171
    	else if (value instanceof StringValueEval) {
172
    	    StringValueEval se = (StringValueEval) value;
173
    		retval = se.getStringValue();
174
    	}
175
    	else {
176
    		retval = value.getClass().getName();
177
    	}
178
    	return retval;
179
	}
180
181
	/**
182
	 * evaluates a formula!!! :)
183
	 * @param formula
184
	 * @param sheet
185
	 * @param workbook
186
	 * @return
187
	 */
188
	private static Eval evaluate(String formula, HSSFSheet sheet, HSSFWorkbook workbook) {
189
		FormulaParser parser = new FormulaParser(formula, workbook.getWorkbook());
190
		parser.parse();
191
		Ptg[] ptgs = parser.getRPNPtg();
192
		// -- parsing over --
193
		
194
    	Stack stack = new Stack();
195
    	for (int i=0, iSize=ptgs.length; i<iSize; i++) {
196
			if (ptgs[i] instanceof ControlPtg) {continue;}
197
			if (ptgs[i] instanceof MemErrPtg) {continue;}
198
			if (ptgs[i] instanceof MissingArgPtg) {continue;}
199
			if (ptgs[i] instanceof NamePtg) {continue;}
200
			if (ptgs[i] instanceof NameXPtg) {continue;}
201
			if (ptgs[i] instanceof UnknownPtg) {continue;}
202
203
			
204
    		if (ptgs[i] instanceof OperationPtg) {
205
    			OperationPtg optg = (OperationPtg) ptgs[i];
206
207
    			if (optg instanceof ParenthesisPtg) {continue;}
208
    			if (optg instanceof AttrPtg) {continue;}
209
    			if (optg instanceof UnionPtg) {continue;}
210
    			
211
    			OperationEval operation = (OperationEval) getOperationEvalForPtg(optg);
212
    			
213
    			int numops = operation.getNumberOfOperands();
214
    			Eval[] ops = new Eval[numops];
215
    			for (int j=numops-1; j>=0; j--) { // storing the ops in reverse order since they are popping ;)
216
    				Eval p = (Eval) stack.pop();
217
    				ops[j] = p;
218
    			}
219
    			Eval opresult = operation.evaluate(ops);
220
    			stack.push(opresult);
221
    		}
222
    		else if (ptgs[i] instanceof ReferencePtg) {
223
    			ReferencePtg ptg = (ReferencePtg) ptgs[i];
224
    			short colnum = ptg.getColumn();
225
    			short rownum = ptg.getRow();
226
    			HSSFRow row = sheet.getRow(rownum);
227
    			HSSFCell cell = (row!=null) ? row.getCell(colnum) : null;
228
    			pushRef2DEval(ptg, stack, cell, sheet, workbook);
229
    		}
230
    		else if (ptgs[i] instanceof Ref3DPtg) {
231
    		    Ref3DPtg ptg = (Ref3DPtg) ptgs[i];
232
    			short colnum = ptg.getColumn();
233
    			short rownum = ptg.getRow();
234
    			HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex());
235
    			HSSFRow row = sheet.getRow(rownum);
236
    			HSSFCell cell = (row!=null) ? row.getCell(colnum) : null;
237
    			pushRef3DEval(ptg, stack, cell, sheet, workbook);
238
    		}
239
    		else if (ptgs[i] instanceof AreaPtg) {
240
				AreaPtg ap = (AreaPtg) ptgs[i];
241
				short row0 = ap.getFirstRow();
242
				short col0 = ap.getFirstColumn();
243
				short row1 = ap.getLastRow();
244
				short col1 = ap.getLastColumn();
245
				ValueEval[] values = new ValueEval[(row1-row0+1)*(col1-col0+1)];
246
				for (short x=row0; sheet!=null && x<row1+1; x++) {
247
					HSSFRow row = sheet.getRow(x);
248
					for (short y=col0; row!=null && y<col1+1; y++) {
249
						values[(x-row0)*(col1-col0+1)+(y-col0)] = getEvalForCell(row.getCell(y), sheet, workbook);
250
					}
251
				}
252
				AreaEval ae = new Area2DEval(ap, values);
253
				stack.push(ae);
254
    		}
255
    		else if (ptgs[i] instanceof Area3DPtg) {
256
				Area3DPtg a3dp = (Area3DPtg) ptgs[i];
257
				short row0 = a3dp.getFirstRow();
258
				short col0 = a3dp.getFirstColumn();
259
				short row1 = a3dp.getLastRow();
260
				short col1 = a3dp.getLastColumn();
261
				HSSFSheet xsheet = workbook.getSheetAt(a3dp.getExternSheetIndex());
262
				ValueEval[] values = new ValueEval[(row1-row0+1)*(col1-col0+1)];
263
				for (short x=row0; sheet!=null && x<row1+1; x++) {
264
					HSSFRow row = sheet.getRow(x);
265
					for (short y=col0; row!=null && y<col1+1; y++) {
266
						values[(x-row0)*(col1-col0+1)+(y-col0)] = getEvalForCell(row.getCell(y), sheet, workbook);
267
					}
268
				}
269
				AreaEval ae = new Area3DEval(a3dp, values);
270
				stack.push(ae);
271
    		}
272
    		else {
273
    		    Eval ptgEval = getEvalForPtg(ptgs[i]);
274
    			stack.push(ptgEval);
275
    		}
276
    	}
277
    	Eval value = ((Eval) stack.pop());
278
    	if (value instanceof RefEval) {
279
    	    RefEval rv = (RefEval) value;
280
    	    value = rv.getInnerValueEval();
281
    	}
282
    	return value;
283
	}
284
	
285
	protected static Eval getOperationEvalForPtg(OperationPtg ptg) {
286
	    Eval retval = null;
287
	    
288
	    Class clazz = (Class) OPERATION_EVALS_MAP.get(ptg.getClass());
289
	    try {
290
		    Constructor constructor = clazz.getConstructor(OPERATION_CONTRUCTOR_CLASS_ARRAY);
291
		    retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg});
292
	    }
293
	    catch (Exception e) {throw new RuntimeException("Fatal Error: ", e);}
294
	    return retval;
295
	}
296
	
297
	
298
	/**
299
	 * returns an appropriate Eval impl instance for the Ptg.
300
	 * The Ptg must be one of: 
301
	 * Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, 
302
	 * NumberPtg, StringPtg, BoolPtg
303
	 * <br/>
304
	 * special Note: OperationPtg subtypes cannot be passed here!
305
	 * @param ptg
306
	 * @return
307
	 */
308
	protected static Eval getEvalForPtg(Ptg ptg) {
309
	    Eval retval = null;
310
	    
311
	    Class clazz = (Class) VALUE_EVALS_MAP.get(ptg.getClass());
312
        try {
313
            if (ptg instanceof Area3DPtg) {
314
                Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
315
                retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg});
316
            }
317
            else if (ptg instanceof AreaPtg) {
318
                Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
319
                retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg});
320
            }
321
            else if (ptg instanceof ReferencePtg) {
322
                Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY);
323
                retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg});
324
            }
325
            else if (ptg instanceof Ref3DPtg) {
326
                Constructor constructor = clazz.getConstructor(REF3D_CONSTRUCTOR_CLASS_ARRAY);
327
                retval = (OperationEval) constructor.newInstance(new Ptg[]{ptg});
328
            }
329
            else {
330
                if (ptg instanceof IntPtg
331
                 || ptg instanceof NumberPtg
332
                 || ptg instanceof StringPtg
333
                 || ptg instanceof BoolPtg
334
                 ) {
335
                    Constructor constructor = clazz.getConstructor(VALUE_CONTRUCTOR_CLASS_ARRAY);
336
            	    retval = (ValueEval) constructor.newInstance(new Ptg[]{ptg});
337
                }
338
            }
339
        } catch (Exception e) {
340
            throw new RuntimeException("Fatal Error: ", e);
341
        }
342
        return retval;
343
344
	}
345
	
346
	/**
347
	 * Given a cell, find its type and from that create an appropriate ValueEval impl instance
348
	 * and return that. Since the cell could be an external reference, we need the sheet that
349
	 * this belongs to.
350
	 * @param cell
351
	 * @param sheet
352
	 * @param workbook
353
	 * @return
354
	 */
355
	protected static ValueEval getEvalForCell(HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) {
356
		ValueEval retval = null;
357
		if (cell != null) {
358
			switch (cell.getCellType()) {
359
			case HSSFCell.CELL_TYPE_NUMERIC:
360
				retval = new NumberEval(cell.getNumericCellValue());
361
				break;
362
			case HSSFCell.CELL_TYPE_STRING:
363
				retval = new StringEval(cell.getStringCellValue());
364
                break;
365
			case HSSFCell.CELL_TYPE_FORMULA:
366
				retval = (ValueEval) evaluate(cell.getCellFormula(), sheet, workbook);
367
				break;
368
			case HSSFCell.CELL_TYPE_BOOLEAN:
369
				retval = new BoolEval(cell.getBooleanCellValue());
370
				break;
371
			case HSSFCell.CELL_TYPE_BLANK:
372
			    retval = new StringEval("");
373
				break;
374
			case HSSFCell.CELL_TYPE_ERROR:
375
				retval = ErrorEval.ERROR_UNKNOWN; // TODO: think about this...
376
				break;
377
			}
378
		}
379
		return retval;
380
	}
381
	
382
	/**
383
	 * create a Ref2DEval for ReferencePtg and push it on the stack.
384
	 * @param ptg
385
	 * @param stack
386
	 * @param cell
387
	 * @param sheet
388
	 * @param workbook
389
	 */
390
	protected static void pushRef2DEval(ReferencePtg ptg, Stack stack, HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) {
391
	    if (cell!=null)
392
	    switch (cell.getCellType()) {
393
		case HSSFCell.CELL_TYPE_NUMERIC:
394
			stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue())));
395
			break;
396
		case HSSFCell.CELL_TYPE_STRING:
397
			stack.push(new Ref2DEval(ptg, new StringEval(cell.getStringCellValue())));
398
			break;
399
		case HSSFCell.CELL_TYPE_FORMULA:
400
			stack.push(evaluate(cell.getCellFormula(), sheet, workbook));
401
			break;
402
		case HSSFCell.CELL_TYPE_BOOLEAN:
403
			stack.push(new Ref2DEval(ptg, new BoolEval(cell.getBooleanCellValue())));
404
			break;
405
		case HSSFCell.CELL_TYPE_BLANK:
406
			stack.push(new Ref2DEval(ptg, new StringEval("")));
407
			break;
408
		case HSSFCell.CELL_TYPE_ERROR:
409
			stack.push(new Ref2DEval(ptg, ErrorEval.ERROR_UNKNOWN)); // TODO: think about this...
410
			break;
411
		}
412
	    else {
413
	        stack.push(new Ref2DEval(ptg, new StringEval("")));
414
	    }
415
	}
416
417
	/**
418
	 * create a Ref3DEval for Ref3DPtg and push it on the stack.
419
	 * @param ptg
420
	 * @param stack
421
	 * @param cell
422
	 * @param sheet
423
	 * @param workbook
424
	 */
425
	protected static void pushRef3DEval(Ref3DPtg ptg, Stack stack, HSSFCell cell, HSSFSheet sheet, HSSFWorkbook workbook) {
426
		if (cell!=null)
427
	    switch (cell.getCellType()) {
428
		case HSSFCell.CELL_TYPE_NUMERIC:
429
			stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue())));
430
			break;
431
		case HSSFCell.CELL_TYPE_STRING:
432
			stack.push(new Ref3DEval(ptg, new StringEval(cell.getStringCellValue())));
433
			break;
434
		case HSSFCell.CELL_TYPE_FORMULA:
435
			stack.push(evaluate(cell.getCellFormula(), sheet, workbook));
436
			break;
437
		case HSSFCell.CELL_TYPE_BOOLEAN:
438
			stack.push(new Ref3DEval(ptg, new BoolEval(cell.getBooleanCellValue())));
439
			break;
440
		case HSSFCell.CELL_TYPE_BLANK:
441
			stack.push(new Ref3DEval(ptg, new StringEval("")));
442
			break;
443
		case HSSFCell.CELL_TYPE_ERROR:
444
			stack.push(new Ref3DEval(ptg, ErrorEval.ERROR_UNKNOWN)); // TODO: think about this...
445
			break;
446
		}
447
		else {
448
		    stack.push(new Ref3DEval(ptg, new StringEval("")));
449
		}
450
	}
451
452
	
453
	
454
	/**
455
	 * Manual testing... needs a c:/temp/test1.xls file to be present.
456
	 * @param args
457
	 * @throws Exception
458
	 */
459
    public static void main(String[] args) throws Exception {
460
    	String FILE_NAME = "c:/temp/test1.xls";
461
    	
462
    	FileInputStream fis = new FileInputStream(FILE_NAME);
463
    	HSSFWorkbook wb = new HSSFWorkbook(fis);
464
    	fis.close();
465
    	HSSFSheet sheet = wb.getSheetAt(0);
466
    	
467
    	for (int rn=1, rnSize=4; rn<=rnSize; rn++) {
468
        	HSSFRow row = sheet.getRow(rn);
469
    	    for (int cn=5, cnSize=7; cn<=cnSize; cn++) {
470
    	    	HSSFCell     	cell = row.getCell((short) cn);
471
    	    	String formula = cell.getCellFormula();
472
    	    	System.out.println("-----------------------------------------------------");
473
    	    	//inspectPtgs(formula, sheet, wb);
474
    	    	System.out.println("["+rn+","+cn+"]: "+evaluateToString(formula, sheet, wb));
475
    	    	System.out.println("-----------------------------------------------------");
476
    	    }
477
    	}
478
    }
479
    
480
}

Return to bug 34828