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

(-)src/documentation/content/xdocs/hssf/eval-devguide.xml (-69 / +85 lines)
Lines 65-160 Link Here
65
	</section>
65
	</section>
66
	<section><title>Walkthrough of an "evaluate()" implementation.</title>
66
	<section><title>Walkthrough of an "evaluate()" implementation.</title>
67
		<p>So here is the fun part - lets walk through the implementation of the excel 
67
		<p>So here is the fun part - lets walk through the implementation of the excel 
68
			function... <strong>AVERAGE()</strong> </p>
68
			function... <strong>SQRT()</strong> </p>
69
		<section><title>The Code</title>
69
		<section><title>The Code</title>
70
		<source>
70
		<source>
71
public Eval evaluate(Eval[] operands) {
71
public class Sqrt extends NumericFunction {
72
    double d = 0;
72
    
73
    int count = 0;
73
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
74
    ValueEval retval = null;
74
        new ValueEvalToNumericXlator((short)
75
    for (int i = 0, iSize = operands.length; i &lt; iSize; i++) {
75
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
76
        if (operands[i] == null) continue;
76
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
77
        if (operands[i] instanceof AreaEval) {
77
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
78
            AreaEval ap = (AreaEval) operands[i];
78
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
79
            Object[] values = ap.getValues();
79
                | ValueEvalToNumericXlator.STRING_IS_PARSED
80
            for (int j = 0, jSize = values.length; j &lt; jSize; j++) {
80
                ));
81
                if (values[j] == null) continue;
81
82
                if (values[j] instanceof NumberEval) {
82
    protected ValueEvalToNumericXlator getXlator() {
83
                //inside areas, ignore bools
83
        return NUM_XLATOR;
84
                    d += ((NumberEval) values[j]).getNumberValue();
84
    }
85
                    count++;
85
86
                }
86
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
87
                else if (values[j] instanceof RefEval) {
87
        double d = 0;
88
                    RefEval re = (RefEval) values[j];
88
        ValueEval retval = null;
89
                    ValueEval ve = re.getInnerValueEval();
89
        
90
                    if (ve != null &amp;&amp; ve instanceof NumberEval) {
90
        switch (operands.length) {
91
                        d += ((NumberEval) ve).getNumberValue();
91
        default:
92
                        count++;
92
            break;
93
                    }
93
        case 1:
94
                }
94
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
95
            if (ve instanceof NumericValueEval) {
96
                NumericValueEval ne = (NumericValueEval) ve;
97
                d = ne.getNumberValue();
95
            }
98
            }
96
        }
99
            else if (ve instanceof BlankEval) {
97
        else if (operands[i] instanceof NumericValueEval) { 
100
                // do nothing
98
            // for direct operands evaluate bools
101
            }
99
            NumericValueEval np = (NumericValueEval) operands[i];
102
            else {
100
            d += np.getNumberValue();
103
                retval = ErrorEval.NUM_ERROR;
101
            count++;
102
        }
103
        else if (operands[i] instanceof RefEval) {
104
            RefEval re = (RefEval) operands[i];
105
            ValueEval ve = re.getInnerValueEval();
106
            if (ve instanceof NumberEval) { 
107
                //if it is a reference, ignore bools
108
                NumberEval ne = (NumberEval) ve;
109
                d += ne.getNumberValue();
110
                count++;
111
            }
104
            }
112
        }
105
        }
106
        
107
        if (retval == null) {
108
            d = Math.sqrt(d);
109
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
110
        }
111
        return retval;
113
    }
112
    }
114
113
115
    if (retval == null) {
116
        retval = (Double.isNaN(d)) ? 
117
          (ValueEval) ErrorEval.ERROR_503 : new NumberEval(d/count);
118
    }
119
    return retval;
120
}
114
}
121
	</source>
115
	</source>
122
		</section>
116
		</section>
123
		<section><title>Implementation Details</title>
117
		<section><title>Implementation Details</title>
124
		<ul>
118
		<ul>
125
			<li>The implementation of the AVERAGE function lives in package 
119
			<li>The implementation of the SQRT() function lives in package 
126
				o.a.p.hssf.record.formula.functions named  Average.java. 
120
				o.a.p.hssf.record.formula.functions named  Sqrt.java. 
127
				(Every excel function has a corresponding java source file 
121
				(Every excel function has a corresponding java source file 
128
				in the above package) </li>
122
				in the above package) </li>
129
			<li>If you open the file for a function thats not yet implemented, you will see one un-implemented method: 
123
			<li>If you open the file for a function thats not yet implemented, you will see one un-implemented method: 
130
				<code>public Eval evaluate(Eval[] operands) {}</code> </li>
124
				<code>public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {}</code> </li>
131
			<li>Since the excel Average() function can take 1 or more operands, we iterate over all operands that are passed in the evaluate method:
125
			<li>Since the excel SQRT() function can take only 1 operand, we do a check on the length of the passed array of operands:
132
				<code>for (int i=0, iSize=operands.length; i&lt;iSize; i++) {...}</code></li>
126
				<code>switch (operands.length) {...}</code></li>
133
			<li>inside the loop, you will do the following
127
			<li>For the valid case (case 1) :
134
				<ol>
128
				<ol>
135
					<li>Do a null check: <code>if (operands[i] == null) continue;</code></li>
129
					<li>Obtain a normlized ValueEval type by:
136
					<li>Figure out the actual subtype of ValueEval that the operands 
130
					<source>ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);</source>
137
						implements. The possible types that you will encounter in an 
131
					The method singleOperandEvaluate(..) is defined in the super class NumericFunction
138
						evaluate() are: NumberEval, BoolEval, StringEval, ErrorEval, 
132
					from which all numeric functions should extend to take advantage of the resusable
139
						AreaEval, RefEval, BlankEval.</li>
133
					singleOperandEvaluate(..) method. Since the operand can be any ValueEval subtype,
140
					<li>Implement the function. See the next section for some
134
					the singleOperandEvaluate reduces the number of types that you will have to
141
						caveats on implementing the Excel semantics. </li>
135
					check for in your code - specifically it limits the checks required to one of
136
					NumericValueEval, BlankEval and ErrorEval types. 
137
					</li>
138
					<li>Other types like StringEval,
139
					BoolEval, AreaEval etc. are converted to one of the 3 types depending on the
140
					flags set in the ValueEvalToNumericXlator instance returned by the Factory
141
					method "getXlator()". The flags are (sort of) self explanatory and the appropriate
142
					flag combination should be chosen for the excel function that you are implementing.
143
					Most functions require the same set of flags, so you may be better off simply copying
144
					the code as given in Sqrt.java for initializing the ValueEvalToNumericXlator and
145
					testing if it works fine.</li>
146
					<li>Finally after you have got the double value that you need to operate on,
147
					do basic checks to see that the Double is not a NaN or Infinite and then perform
148
					the math operation. After the math operation is performed, check the double value
149
					to see if it has become NaN or Infinite as a result of the operation.</li>
142
				</ol>
150
				</ol>
143
			</li>
151
			</li>
144
			<li>Finally before returning the NumberEval wrapping the double value that 
152
			<li>Usually, erroneous conditions are represented by ErrorEval.VALUE_INVALID in case of numeric
145
				you computed, do one final check to see if the double is a NaN, 
153
			operations and ErrorEval.NAME_INVALID in case of string operations. But special cases in numeric
146
				if it is return ErrorEval.ERROR_503 (see the javadoc in ErrorEval.java 
154
			operations can cause other errors like DIV_ZERO or NUM_INVALID. Refer to excel function reference
147
				for description of error codes - it is html so you might as well 
155
			or figure those out by trial and error. At this stage, it may not be feasible to trap error conditions
148
				generate the javadocs)</li>
156
			with the exact error code so VALUE_INVALID or NAME_INVALID could be the default ErrorEval types.</li>
149
			
157
			
150
		</ul>
158
		</ul>
151
		</section>
159
		</section>
152
		<section><title>Modelling Excel Semantics</title>
160
		<section><title>Modelling Excel Semantics</title>
153
			<p>Strings are ignored. Booleans are ignored!!! (damn Oo.o!  I was almost misled here - nevermind). Actually here's the info on Bools: 
161
			<p>Strings are ignored. Booleans are ignored!!!. Actually here's the info on Bools: 
154
				if you have formula: "=TRUE+1", it evaluates to 2. 
162
				if you have formula: "=TRUE+1", it evaluates to 2. 
155
				So also, when you use TRUE like this: "=SUM(1,TRUE)", you see the result is: 2. 
163
				So also, when you use TRUE like this: "=SUM(1,TRUE)", you see the result is: 2. 
156
				So TRUE means 1 when doing numeric calculations, right? 
164
				So TRUE means 1 when doing numeric calculations, right? 
157
				Wrong!
165
				Not quite...
158
				Because when you use TRUE in referenced cells with arithmetic functions, it evaluates to blank - meaning it is not evaluated - as if it was string or a blank cell. 
166
				Because when you use TRUE in referenced cells with arithmetic functions, it evaluates to blank - meaning it is not evaluated - as if it was string or a blank cell. 
159
				eg. "=SUM(1,A1)" when A1 is TRUE evaluates to 1.
167
				eg. "=SUM(1,A1)" when A1 is TRUE evaluates to 1.
160
				So you have to do this kind of check for every possible data type as a function argument for any function before you understand the behaviour of the function. The operands can be entered in excel as comma separated or as a region specified like: A2:D4. Regions are treated as a single token by the parser hence we have AreaEval which stores the ValueEval at each cell in a region in a 1D array. So in our function if the operand is of type AreaEval we need to get the array of ValueEvals in the region of the AreaEval and iterate over each of them as if each of them were individual operands to the AVERAGE function. 
168
				So you have to do this kind of check for every possible data type as a function argument for any function before you understand the behaviour of the function. The operands can be entered in excel as comma separated or as a region specified like: A2:D4. Regions are treated as a single token by the parser hence we have AreaEval which stores the ValueEval at each cell in a region in a 1D array. So in our function if the operand is of type AreaEval we need to get the array of ValueEvals in the region of the AreaEval and iterate over each of them as if each of them were individual operands to the AVERAGE function. 
Lines 164-175 Link Here
164
						Hence BoolEval and NumberEval both implement a common interface: 
172
						Hence BoolEval and NumberEval both implement a common interface: 
165
						NumericValueEval (since numbers and bools are also valid string 
173
						NumericValueEval (since numbers and bools are also valid string 
166
						values, they also implement StringValueEval interface which is 
174
						values, they also implement StringValueEval interface which is 
167
						also implemented by StringEval).</p>
175
						also implemented by StringEval). To handle all such scenarios in a reusable manner,
168
			<p>
176
						there is a helper class NumericFunction from which all numeric function impl classes
177
						should extend. This class normalizes the several ValueEval subtypes to a limited
178
						set of ValueEval subtypes and its behaviour is configurable by a set of flags that
179
						can be bitwise OR-ed to combine them. To better understand how functions should
180
						extend from NumericFunction, see an example implementation in Sqrt.java or Int.java</p>
181
			<p>Other notes:
169
			The ValueEval inside an AreaEval can be one of: 
182
			The ValueEval inside an AreaEval can be one of: 
170
				NumberEval, BoolEval, StringEval, ErrorEval, BlankEval. 
183
				NumberEval, BoolEval, StringEval, ErrorEval, BlankEval. 
171
			So you must handle each of these cases. 
184
			So each of these cases needs to be handled. However for numeric functions, this is done in the super class if you
172
			Similarly, RefEvals have a property: innerValueEval that returns the ValueEval at the referenced cell. The ValueEval inside a RefEval can be one of: NumberEval, BoolEval, StringEval, ErrorEval, BlankEval. So you must handle each of these cases  - see how excel treats each one of them.
185
			call singleOperandEvaluate(..) 
186
			Similarly, RefEvals have a property: innerValueEval that returns the ValueEval at the referenced cell. 
187
			The ValueEval inside a RefEval can be one of: NumberEval, BoolEval, StringEval, ErrorEval, BlankEval. 
188
			Again, for numeric functions this is done in the method super.singleOperandEvaluate(..).
173
			</p>				
189
			</p>				
174
190
175
		</section>
191
		</section>
(-)src/documentation/content/xdocs/hssf/eval.xml (-2 / +10 lines)
Lines 41-51 Link Here
41
FileInputStream fis = new FileInputStream("c:/temp/test.xls");
41
FileInputStream fis = new FileInputStream("c:/temp/test.xls");
42
HSSFWorkbook wb = new HSSFWorkbook(fis);
42
HSSFWorkbook wb = new HSSFWorkbook(fis);
43
HSSFSheet sheet = wb.getSheetAt(0);
43
HSSFSheet sheet = wb.getSheetAt(0);
44
<strong>
44
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
45
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
45
46
</strong>
46
// suppose your formula is in B3
47
// suppose your formula is in B3
47
CellReference cellReference = new CellReference("B3"); 
48
CellReference cellReference = new CellReference("B3"); 
48
HSSFRow row = sheet.getRow(cellReference.getRow());
49
HSSFRow row = sheet.getRow(cellReference.getRow());
50
<strong>
51
evaluator.setCurrentRow(row);
52
</strong>
49
HSSFCell cell = row.getCell(cellReference.getCol()); 
53
HSSFCell cell = row.getCell(cellReference.getCol()); 
50
String formulaString = c.getCellFormula();
54
String formulaString = c.getCellFormula();
51
HSSFFormulaEvaluator.CellValue cellValue = 
55
HSSFFormulaEvaluator.CellValue cellValue = 
Lines 86-96 Link Here
86
FileInputStream fis = new FileInputStream("c:/temp/test.xls");
90
FileInputStream fis = new FileInputStream("c:/temp/test.xls");
87
HSSFWorkbook wb = new HSSFWorkbook(fis);
91
HSSFWorkbook wb = new HSSFWorkbook(fis);
88
HSSFSheet sheet = wb.getSheetAt(0);
92
HSSFSheet sheet = wb.getSheetAt(0);
93
<strong>
89
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
94
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
90
95
</strong>
91
// suppose your formula is in B3
96
// suppose your formula is in B3
92
CellReference cellReference = new CellReference("B3"); 
97
CellReference cellReference = new CellReference("B3"); 
93
HSSFRow row = sheet.getRow(cellReference.getRow());
98
HSSFRow row = sheet.getRow(cellReference.getRow());
99
<strong>
100
evaluator.setCurrentRow(row);
101
</strong>
94
HSSFCell cell = row.getCell(cellReference.getCol()); 
102
HSSFCell cell = row.getCell(cellReference.getCol()); 
95
String formulaString = c.getCellFormula();
103
String formulaString = c.getCellFormula();
96
104
(-)src/java/org/apache/poi/hssf/model/FormulaParser.java (-1 / +6 lines)
Lines 115-121 Link Here
115
    private void Abort(String s) {
115
    private void Abort(String s) {
116
        Error(s);
116
        Error(s);
117
        //System.exit(1);  //throw exception??
117
        //System.exit(1);  //throw exception??
118
        throw new RuntimeException("Cannot Parse, sorry : "+s);
118
        throw new RuntimeException("Cannot Parse, sorry : "+s + " [Formula String was: '"+formulaString+"']");
119
    }
119
    }
120
    
120
    
121
    
121
    
Lines 466-471 Link Here
466
    		Factor();
466
    		Factor();
467
    		tokens.add(new UnaryMinusPtg());
467
    		tokens.add(new UnaryMinusPtg());
468
    	}
468
    	}
469
        else if (look == '+') {
470
            Match('+');
471
            Factor();
472
            tokens.add(new UnaryPlusPtg());
473
        }
469
        else if (look == '(' ) {
474
        else if (look == '(' ) {
470
            Match('(');
475
            Match('(');
471
            Expression();
476
            Expression();
(-).settings/com.genuitec.jboss.ide.eclipse.xdoclet.run.prefs (+3 lines)
Added Link Here
1
#Sat May 14 15:29:09 EDT 2005
2
eclipse.preferences.version=1
3
xdoclet.build.policy=automatic
(-).settings/org.eclipse.pde.core.prefs (+3 lines)
Added Link Here
1
#Sat May 14 15:29:12 EDT 2005
2
eclipse.preferences.version=1
3
selfhosting.binExcludes=/jakarta-poi/bin
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AddEval.java (+81 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.AddPtg;
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
 * This is a documentation of the observed behaviour of 
13
 * the '+' operator in Excel:
14
 * <ol>
15
 * <li> 1+TRUE = 2
16
 * <li> 1+FALSE = 1
17
 * <li> 1+"true" = #VALUE!
18
 * <li> 1+"1" = 2
19
 * <li> 1+A1 = #VALUE if A1 contains "1"
20
 * <li> 1+A1 = 2 if A1 contains ="1"
21
 * <li> 1+A1 = 2 if A1 contains TRUE or =TRUE
22
 * <li> 1+A1 = #VALUE! if A1 contains "TRUE" or ="TRUE"
23
 */
24
public class AddEval extends NumericOperationEval {
25
26
    private AddPtg delegate;
27
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
28
        new ValueEvalToNumericXlator((short)
29
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
30
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
31
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
32
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
33
                | ValueEvalToNumericXlator.STRING_IS_PARSED
34
                ));
35
36
    public AddEval(Ptg ptg) {
37
        delegate = (AddPtg) ptg;
38
    }
39
40
    public ValueEvalToNumericXlator getXlator() {
41
        return NUM_XLATOR;
42
    }
43
    
44
    
45
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
46
        Eval retval = null;
47
        double d = 0;
48
        switch (operands.length) {
49
        default: // will rarely happen. currently the parser itself fails.
50
            retval = ErrorEval.UNKNOWN_ERROR;
51
            break;
52
        case 2:
53
            for (int i = 0, iSize = 2; retval==null && i < iSize; i++) {
54
                ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
55
                if (ve instanceof NumericValueEval) {
56
                    d += ((NumericValueEval) ve).getNumberValue();
57
                }
58
                else if (ve instanceof BlankEval) {
59
                    // do nothing
60
                }
61
                else {
62
                    retval = ErrorEval.VALUE_INVALID;
63
                }
64
            } // end for inside case
65
        } // end switch
66
        
67
        if (retval == null) {
68
            retval = Double.isNaN(d) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
69
        }
70
71
        return retval;
72
    }
73
74
    public int getNumberOfOperands() {
75
        return delegate.getNumberOfOperands();
76
    }
77
78
    public int getType() {
79
        return delegate.getType();
80
    }
81
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java (+75 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
18
    private ValueEval[] values;
19
20
    public Area2DEval(Ptg ptg, ValueEval[] values) {
21
        this.delegate = (AreaPtg) ptg;
22
        this.values = values;
23
    }
24
25
    public short getFirstColumn() {
26
        return delegate.getFirstColumn();
27
    }
28
29
    public int getFirstRow() {
30
        return delegate.getFirstRow();
31
    }
32
33
    public short getLastColumn() {
34
        return delegate.getLastColumn();
35
    }
36
37
    public int getLastRow() {
38
        return delegate.getLastRow();
39
    }
40
41
    public ValueEval[] getValues() {
42
        return values;
43
    }
44
    
45
    public ValueEval getValueAt(int row, short col) {
46
        ValueEval retval;
47
        int index = ((row-getFirstRow())*(getLastColumn()-getFirstColumn()+1))+(col-getFirstColumn());
48
        if (index <0 || index >= values.length)
49
            retval = ErrorEval.VALUE_INVALID;
50
        else 
51
            retval = values[index];
52
        return retval;
53
    }
54
    
55
    public boolean contains(int row, short col) {
56
        return (getFirstRow() <= row) && (getLastRow() >= row) 
57
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
58
    }
59
    
60
    public boolean containsRow(int row) {
61
        return (getFirstRow() <= row) && (getLastRow() >= row);
62
    }
63
    
64
    public boolean containsColumn(short col) {
65
        return (getFirstColumn() <= col) && (getLastColumn() >= col);
66
    }
67
    
68
    public boolean isColumn() {
69
        return delegate.getFirstColumn() == delegate.getLastColumn();
70
    }
71
72
    public boolean isRow() {
73
        return delegate.getFirstRow() == delegate.getLastRow();
74
    }
75
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java (+77 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.Area3DPtg;
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 Area3DEval implements AreaEval {
15
16
    private Area3DPtg delegate;
17
18
    private ValueEval[] values;
19
20
    public Area3DEval(Ptg ptg, ValueEval[] values) {
21
        this.values = values;
22
        this.delegate = (Area3DPtg) ptg;
23
    }
24
25
    public short getFirstColumn() {
26
        return delegate.getFirstColumn();
27
    }
28
29
    public int getFirstRow() {
30
        return delegate.getFirstRow();
31
    }
32
33
    public short getLastColumn() {
34
        return delegate.getLastColumn();
35
    }
36
37
    public int getLastRow() {
38
        return delegate.getLastRow();
39
    }
40
41
    public ValueEval[] getValues() {
42
        return values;
43
    }
44
    
45
    public ValueEval getValueAt(int row, short col) {
46
        ValueEval retval;
47
        int index = (row-getFirstRow())*(col-getFirstColumn());
48
        if (index <0 || index >= values.length)
49
            retval = ErrorEval.VALUE_INVALID;
50
        else 
51
            retval = values[index];
52
        return retval;
53
    }
54
    
55
    public boolean contains(int row, short col) {
56
        return (getFirstRow() <= row) && (getLastRow() >= row) 
57
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
58
    }
59
    
60
    public boolean containsRow(int row) {
61
        return (getFirstRow() <= row) && (getLastRow() >= row);
62
    }
63
    
64
    public boolean containsColumn(short col) {
65
        return (getFirstColumn() <= col) && (getLastColumn() >= col);
66
    }
67
    
68
    
69
    public boolean isColumn() {
70
        return delegate.getFirstColumn() == delegate.getLastColumn();
71
    }
72
73
    public boolean isRow() {
74
        return delegate.getFirstRow() == delegate.getLastRow();
75
    }
76
77
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java (+100 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 ValueEval {
12
13
    /**
14
     * returns the 0-based index of the first row in
15
     * this area.
16
     * @return
17
     */
18
    public int getFirstRow();
19
20
    /**
21
     * returns the 0-based index of the last row in
22
     * this area.
23
     * @return
24
     */
25
    public int getLastRow();
26
27
    /**
28
     * returns the 0-based index of the first col in
29
     * this area.
30
     * @return
31
     */
32
    public short getFirstColumn();
33
34
    /**
35
     * returns the 0-based index of the last col in
36
     * this area.
37
     * @return
38
     */
39
    public short getLastColumn();
40
    
41
    /**
42
     * returns true if the Area's start and end row indexes
43
     * are same. This result of this method should agree
44
     * with getFirstRow() == getLastRow().
45
     * @return
46
     */
47
    public boolean isRow();
48
    
49
    /**
50
     * returns true if the Area's start and end col indexes
51
     * are same. This result of this method should agree
52
     * with getFirstColumn() == getLastColumn().
53
     * @return
54
     */
55
    public boolean isColumn();
56
57
    /**
58
     * The array of values  in this area. Although the area
59
     * maybe 1D (ie. isRow() or isColumn() returns true) or 2D
60
     * the returned array is 1D.
61
     * @return
62
     */
63
    public ValueEval[] getValues();
64
65
    /**
66
     * returns the ValueEval from the values array at the specified 
67
     * row and col index. The specified indexes should be absolute indexes
68
     * in the sheet and not relative indexes within the area. Also,
69
     * if contains(row, col) evaluates to true, a null value will
70
     * bre returned.
71
     * @param row
72
     * @param col
73
     * @return
74
     */
75
    public ValueEval getValueAt(int row, short col);
76
    
77
    /**
78
     * returns true if the cell at row and col specified 
79
     * as absolute indexes in the sheet is contained in 
80
     * this area.
81
     * @param row
82
     * @param col
83
     * @return
84
     */
85
    public boolean contains(int row, short col);
86
    
87
    /**
88
     * returns true if the specified col is in range
89
     * @param col
90
     * @return
91
     */
92
    public boolean containsColumn(short col);
93
    
94
    /**
95
     * returns true if the specified row is in range
96
     * @param row
97
     * @return
98
     */
99
    public boolean containsRow(int row);
100
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BlankEval.java (+17 lines)
Added Link Here
1
/*
2
 * Created on May 9, 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; This class is a
9
 *         marker class. It is a special value for empty cells.
10
 */
11
public class BlankEval implements ValueEval {
12
13
    public static BlankEval INSTANCE = new BlankEval();
14
15
    private BlankEval() {
16
    }
17
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/BoolEval.java (+41 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 static final BoolEval FALSE = new BoolEval(false);
19
    
20
    public static final BoolEval TRUE = new BoolEval(true);
21
22
    public BoolEval(Ptg ptg) {
23
        this.value = ((BoolPtg) ptg).getValue();
24
    }
25
26
    private BoolEval(boolean value) {
27
        this.value = value;
28
    }
29
30
    public boolean getBooleanValue() {
31
        return value;
32
    }
33
34
    public double getNumberValue() {
35
        return value ? (short) 1 : (short) 0;
36
    }
37
38
    public String getStringValue() {
39
        return value ? "TRUE" : "FALSE";
40
    }
41
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ConcatEval.java (+61 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 extends StringOperationEval {
15
16
    private ConcatPtg delegate;
17
18
    public ConcatEval(Ptg ptg) {
19
        this.delegate = (ConcatPtg) ptg;
20
    }
21
22
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
23
        Eval retval = null;
24
        StringBuffer sb = null;
25
        
26
        switch (operands.length) {
27
        default: // paranoid check :)
28
            retval = ErrorEval.UNKNOWN_ERROR;
29
            break;
30
        case 2:
31
            sb = new StringBuffer();
32
            for (int i = 0, iSize = 2; retval == null && i < iSize; i++) { 
33
                
34
                ValueEval ve = singleOperandEvaluate(operands[i], srcRow, srcCol);
35
                if (ve instanceof StringValueEval) {
36
                    StringValueEval sve = (StringValueEval) ve;
37
                    sb.append(sve.getStringValue());
38
                }
39
                else if (ve instanceof BlankEval) {
40
                    // do nothing
41
                }
42
                else { // must be an error eval
43
                    retval = ve;
44
                }
45
            }
46
        }
47
        
48
        if (retval == null) {
49
            retval = new StringEval(sb.toString());
50
        }
51
        return retval;
52
    }
53
54
    public int getNumberOfOperands() {
55
        return delegate.getNumberOfOperands();
56
    }
57
58
    public int getType() {
59
        return delegate.getType();
60
    }
61
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/DivideEval.java (+86 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.DividePtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *  
13
 */
14
public class DivideEval extends NumericOperationEval {
15
16
    private DividePtg delegate;
17
18
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
19
        new ValueEvalToNumericXlator((short)
20
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
21
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
22
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
23
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
24
                | ValueEvalToNumericXlator.STRING_IS_PARSED
25
                ));
26
27
    public DivideEval(Ptg ptg) {
28
        delegate = (DividePtg) ptg;
29
    }
30
    
31
    protected ValueEvalToNumericXlator getXlator() {
32
        return NUM_XLATOR;
33
    }
34
35
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
36
        Eval retval = null;
37
        double d0 = 0;
38
        double d1 = 0;
39
        switch (operands.length) {
40
        default: // will rarely happen. currently the parser itself fails.
41
            retval = ErrorEval.UNKNOWN_ERROR;
42
            break;
43
        case 2:
44
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
45
            if (ve instanceof NumericValueEval) {
46
                d0 = ((NumericValueEval) ve).getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.VALUE_INVALID;
53
            }
54
            
55
            if (retval == null) { // no error yet
56
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
57
                if (ve instanceof NumericValueEval) {
58
                    d1 = ((NumericValueEval) ve).getNumberValue();
59
                }
60
                else if (ve instanceof BlankEval) {
61
                    // do nothing
62
                }
63
                else {
64
                    retval = ErrorEval.VALUE_INVALID;
65
                }
66
            }
67
        } // end switch
68
69
        if (retval == null) {
70
            retval = (d1 == 0) 
71
                ? ErrorEval.DIV_ZERO
72
                : (Double.isNaN(d0) || Double.isNaN(d1)) 
73
                    ? (ValueEval) ErrorEval.VALUE_INVALID 
74
                    : new NumberEval(d0 / d1);
75
        }
76
        return retval;
77
    }
78
79
    public int getNumberOfOperands() {
80
        return delegate.getNumberOfOperands();
81
    }
82
83
    public int getType() {
84
        return delegate.getType();
85
    }
86
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/EqualEval.java (+51 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 extends RelationalOperationEval {
15
16
    private EqualPtg delegate;
17
18
    public EqualEval(Ptg ptg) {
19
        this.delegate = (EqualPtg) ptg;
20
    }
21
22
    
23
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
24
        ValueEval retval = null;
25
        
26
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
27
        retval = rvs.ee;
28
        int result = 0;
29
        if (retval == null) {
30
            result = doComparison(rvs.bs);
31
            if (result == 0) {
32
                result = doComparison(rvs.ss);
33
            }
34
            if (result == 0) {
35
                result = doComparison(rvs.ds);
36
            }
37
38
            retval = (result == 0) ? BoolEval.TRUE : BoolEval.FALSE;
39
        }
40
41
        return retval;
42
    }
43
44
    public int getNumberOfOperands() {
45
        return delegate.getNumberOfOperands();
46
    }
47
48
    public int getType() {
49
        return delegate.getType();
50
    }
51
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/ErrorEval.java (+609 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
 * Error code reference from OpenOffice documentation: <br/><TABLE WIDTH=575
11
 * BORDER=1 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#ffffff"> <COL WIDTH=42> <COL
12
 * WIDTH=118> <COL WIDTH=401>
13
 * <TR VALIGN=TOP>
14
 * <TD WIDTH=42 BGCOLOR="#ffffff">
15
 * <P CLASS="tablehead" ALIGN=LEFT>
16
 * Error Code
17
 * </P>
18
 * </TD>
19
 * <TD WIDTH=118 BGCOLOR="#ffffff">
20
 * <P CLASS="tablehead" ALIGN=LEFT>
21
 * Message
22
 * </P>
23
 * </TD>
24
 * <TD WIDTH=401 BGCOLOR="#ffffff">
25
 * <P CLASS="tablehead" ALIGN=LEFT>
26
 * Explanation
27
 * </P>
28
 * </TD>
29
 * </TR>
30
 * <TR VALIGN=TOP>
31
 * <TD WIDTH=42 BGCOLOR="#ffffff">
32
 * <P CLASS="textintable" ALIGN=LEFT>
33
 * 501
34
 * </P>
35
 * </TD>
36
 * <TD WIDTH=118 BGCOLOR="#ffffff">
37
 * <P CLASS="textintable" ALIGN=LEFT>
38
 * Invalid character
39
 * </P>
40
 * </TD>
41
 * <TD WIDTH=401 BGCOLOR="#ffffff">
42
 * <P CLASS="textintable" ALIGN=LEFT>
43
 * Character in a formula is not valid, for example, &quot;=1Eq&quot; instead of
44
 * &quot;=1E2&quot;.
45
 * </P>
46
 * </TD>
47
 * </TR>
48
 * <TR VALIGN=TOP>
49
 * <TD WIDTH=42 BGCOLOR="#ffffff">
50
 * <P CLASS="textintable" ALIGN=LEFT>
51
 * 502
52
 * </P>
53
 * </TD>
54
 * <TD WIDTH=118 BGCOLOR="#ffffff">
55
 * <P CLASS="textintable" ALIGN=LEFT>
56
 * Invalid argument
57
 * </P>
58
 * </TD>
59
 * <TD WIDTH=401 BGCOLOR="#ffffff">
60
 * <P CLASS="textintable" ALIGN=LEFT>
61
 * Function argument is not valid, for example, a negative number for the root
62
 * function.
63
 * </P>
64
 * </TD>
65
 * </TR>
66
 * <TR VALIGN=TOP>
67
 * <TD WIDTH=42 BGCOLOR="#ffffff">
68
 * <P CLASS="textintable" ALIGN=LEFT>
69
 * 503
70
 * </P>
71
 * </TD>
72
 * <TD WIDTH=118 BGCOLOR="#ffffff">
73
 * <P CLASS="textintable" ALIGN=LEFT>
74
 * Invalid floating point operation
75
 * </P>
76
 * </TD>
77
 * <TD WIDTH=401 BGCOLOR="#ffffff">
78
 * <P CLASS="textintable" ALIGN=LEFT>
79
 * Division by 0, or another calculation that results in an overflow of the
80
 * defined value range.
81
 * </P>
82
 * </TD>
83
 * </TR>
84
 * <TR VALIGN=TOP>
85
 * <TD WIDTH=42 BGCOLOR="#ffffff">
86
 * <P CLASS="textintable" ALIGN=LEFT>
87
 * 504
88
 * </P>
89
 * </TD>
90
 * <TD WIDTH=118 BGCOLOR="#ffffff">
91
 * <P CLASS="textintable" ALIGN=LEFT>
92
 * Parameter list error
93
 * </P>
94
 * </TD>
95
 * <TD WIDTH=401 BGCOLOR="#ffffff">
96
 * <P CLASS="textintable" ALIGN=LEFT>
97
 * Function parameter is not valid, for example, text instead of a number, or a
98
 * domain reference instead of cell reference.
99
 * </P>
100
 * </TD>
101
 * </TR>
102
 * <TR VALIGN=TOP>
103
 * <TD WIDTH=42 BGCOLOR="#ffffff">
104
 * <P CLASS="textintable" ALIGN=LEFT>
105
 * 505
106
 * </P>
107
 * </TD>
108
 * <TD WIDTH=118 BGCOLOR="#ffffff">
109
 * <P CLASS="textintable" ALIGN=LEFT>
110
 * Internal syntax error
111
 * </P>
112
 * </TD>
113
 * <TD WIDTH=401 BGCOLOR="#ffffff">
114
 * <P CLASS="textintable" ALIGN=LEFT>
115
 * Not used
116
 * </P>
117
 * </TD>
118
 * </TR>
119
 * <TR VALIGN=TOP>
120
 * <TD WIDTH=42 BGCOLOR="#ffffff">
121
 * <P CLASS="textintable" ALIGN=LEFT>
122
 * 506
123
 * </P>
124
 * </TD>
125
 * <TD WIDTH=118 BGCOLOR="#ffffff">
126
 * <P CLASS="textintable" ALIGN=LEFT>
127
 * Invalid semicolon
128
 * </P>
129
 * </TD>
130
 * <TD WIDTH=401 BGCOLOR="#ffffff">
131
 * <P CLASS="textintable" ALIGN=LEFT>
132
 * Not used
133
 * </P>
134
 * </TD>
135
 * </TR>
136
 * <TR VALIGN=TOP>
137
 * <TD WIDTH=42 BGCOLOR="#ffffff">
138
 * <P CLASS="textintable" ALIGN=LEFT>
139
 * 507
140
 * </P>
141
 * </TD>
142
 * <TD WIDTH=118 BGCOLOR="#ffffff">
143
 * <P CLASS="textintable" ALIGN=LEFT>
144
 * Error: Pair missing
145
 * </P>
146
 * </TD>
147
 * <TD WIDTH=401 BGCOLOR="#ffffff">
148
 * <P CLASS="textintable" ALIGN=LEFT>
149
 * Not used
150
 * </P>
151
 * </TD>
152
 * </TR>
153
 * <TR VALIGN=TOP>
154
 * <TD WIDTH=42 BGCOLOR="#ffffff">
155
 * <P CLASS="textintable" ALIGN=LEFT>
156
 * 508
157
 * </P>
158
 * </TD>
159
 * <TD WIDTH=118 BGCOLOR="#ffffff">
160
 * <P CLASS="textintable" ALIGN=LEFT>
161
 * Error: Pair missing
162
 * </P>
163
 * </TD>
164
 * <TD WIDTH=401 BGCOLOR="#ffffff">
165
 * <P CLASS="textintable" ALIGN=LEFT>
166
 * Missing bracket, for example, closing brackets, but no opening brackets
167
 * </P>
168
 * </TD>
169
 * </TR>
170
 * <TR VALIGN=TOP>
171
 * <TD WIDTH=42 BGCOLOR="#ffffff">
172
 * <P CLASS="textintable" ALIGN=LEFT>
173
 * 509
174
 * </P>
175
 * </TD>
176
 * <TD WIDTH=118 BGCOLOR="#ffffff">
177
 * <P CLASS="textintable" ALIGN=LEFT>
178
 * Missing operator
179
 * </P>
180
 * </TD>
181
 * <TD WIDTH=401 BGCOLOR="#ffffff">
182
 * <P CLASS="textintable" ALIGN=LEFT>
183
 * Operator is missing, for example, &quot;=2(3+4) * &quot;, where the operator
184
 * between &quot;2&quot; and &quot;(&quot; is missing.
185
 * </P>
186
 * </TD>
187
 * </TR>
188
 * <TR VALIGN=TOP>
189
 * <TD WIDTH=42 BGCOLOR="#ffffff">
190
 * <P CLASS="textintable" ALIGN=LEFT>
191
 * 510
192
 * </P>
193
 * </TD>
194
 * <TD WIDTH=118 BGCOLOR="#ffffff">
195
 * <P CLASS="textintable" ALIGN=LEFT>
196
 * Missing variable
197
 * </P>
198
 * </TD>
199
 * <TD WIDTH=401 BGCOLOR="#ffffff">
200
 * <P CLASS="textintable" ALIGN=LEFT>
201
 * Variable is missing, for example when two operators are together
202
 * &quot;=1+*2&quot;.
203
 * </P>
204
 * </TD>
205
 * </TR>
206
 * <TR VALIGN=TOP>
207
 * <TD WIDTH=42 BGCOLOR="#ffffff">
208
 * <P CLASS="textintable" ALIGN=LEFT>
209
 * 511
210
 * </P>
211
 * </TD>
212
 * <TD WIDTH=118 BGCOLOR="#ffffff">
213
 * <P CLASS="textintable" ALIGN=LEFT>
214
 * Missing variable
215
 * </P>
216
 * </TD>
217
 * <TD WIDTH=401 BGCOLOR="#ffffff">
218
 * <P CLASS="textintable" ALIGN=LEFT>
219
 * Function requires more variables than are provided, for example, AND() and
220
 * OR().
221
 * </P>
222
 * </TD>
223
 * </TR>
224
 * <TR VALIGN=TOP>
225
 * <TD WIDTH=42 BGCOLOR="#ffffff">
226
 * <P CLASS="textintable" ALIGN=LEFT>
227
 * 512
228
 * </P>
229
 * </TD>
230
 * <TD WIDTH=118 BGCOLOR="#ffffff">
231
 * <P CLASS="textintable" ALIGN=LEFT>
232
 * Formula overflow
233
 * </P>
234
 * </TD>
235
 * <TD WIDTH=401 BGCOLOR="#ffffff">
236
 * <P CLASS="textintable" ALIGN=LEFT>
237
 * <B>Compiler: </B> the total number of internal tokens, (that is, operators,
238
 * variables, brackets) in the formula exceeds 512. <B>Interpreter: </B> the
239
 * total number of matrices that the formula creates exceeds 150. This includes
240
 * basic functions that receive too large an array as a parameter (max. 0xFFFE,
241
 * for example, 65534 bytes).
242
 * </P>
243
 * </TD>
244
 * </TR>
245
 * <TR VALIGN=TOP>
246
 * <TD WIDTH=42 BGCOLOR="#ffffff">
247
 * <P CLASS="textintable" ALIGN=LEFT>
248
 * 513
249
 * </P>
250
 * </TD>
251
 * <TD WIDTH=118 BGCOLOR="#ffffff">
252
 * <P CLASS="textintable" ALIGN=LEFT>
253
 * String overflow
254
 * </P>
255
 * </TD>
256
 * <TD WIDTH=401 BGCOLOR="#ffffff">
257
 * <P CLASS="textintable" ALIGN=LEFT>
258
 * <B>Compiler: </B> an identifier in the formula exceeds 64 KB in size.
259
 * <B>Interpreter: </B> a result of a string operation exceeds 64 KB in size.
260
 * </P>
261
 * </TD>
262
 * </TR>
263
 * <TR VALIGN=TOP>
264
 * <TD WIDTH=42 BGCOLOR="#ffffff">
265
 * <P CLASS="textintable" ALIGN=LEFT>
266
 * 514
267
 * </P>
268
 * </TD>
269
 * <TD WIDTH=118 BGCOLOR="#ffffff">
270
 * <P CLASS="textintable" ALIGN=LEFT>
271
 * Internal overflow
272
 * </P>
273
 * </TD>
274
 * <TD WIDTH=401 BGCOLOR="#ffffff">
275
 * <P CLASS="textintable" ALIGN=LEFT>
276
 * Sort operation attempted on too much numerical data (max. 100000) or a
277
 * calculation stack overflow.
278
 * </P>
279
 * </TD>
280
 * </TR>
281
 * <TR VALIGN=TOP>
282
 * <TD WIDTH=42 BGCOLOR="#ffffff">
283
 * <P CLASS="textintable" ALIGN=LEFT>
284
 * 515
285
 * </P>
286
 * </TD>
287
 * <TD WIDTH=118 BGCOLOR="#ffffff">
288
 * <P CLASS="textintable" ALIGN=LEFT>
289
 * Internal syntax error
290
 * </P>
291
 * </TD>
292
 * <TD WIDTH=401 BGCOLOR="#ffffff">
293
 * <P CLASS="textintable" ALIGN=LEFT>
294
 * Not used
295
 * </P>
296
 * </TD>
297
 * </TR>
298
 * <TR VALIGN=TOP>
299
 * <TD WIDTH=42 BGCOLOR="#ffffff">
300
 * <P CLASS="textintable" ALIGN=LEFT>
301
 * 516
302
 * </P>
303
 * </TD>
304
 * <TD WIDTH=118 BGCOLOR="#ffffff">
305
 * <P CLASS="textintable" ALIGN=LEFT>
306
 * Internal syntax error
307
 * </P>
308
 * </TD>
309
 * <TD WIDTH=401 BGCOLOR="#ffffff">
310
 * <P CLASS="textintable" ALIGN=LEFT>
311
 * Matrix is expected on the calculation stack, but is not available.
312
 * </P>
313
 * </TD>
314
 * </TR>
315
 * <TR VALIGN=TOP>
316
 * <TD WIDTH=42 BGCOLOR="#ffffff">
317
 * <P CLASS="textintable" ALIGN=LEFT>
318
 * 517
319
 * </P>
320
 * </TD>
321
 * <TD WIDTH=118 BGCOLOR="#ffffff">
322
 * <P CLASS="textintable" ALIGN=LEFT>
323
 * Internal syntax error
324
 * </P>
325
 * </TD>
326
 * <TD WIDTH=401 BGCOLOR="#ffffff">
327
 * <P CLASS="textintable" ALIGN=LEFT>
328
 * Unknown code, for example, a document with a newer function is loaded in an
329
 * older version that does not contain the function.
330
 * </P>
331
 * </TD>
332
 * </TR>
333
 * <TR VALIGN=TOP>
334
 * <TD WIDTH=42 BGCOLOR="#ffffff">
335
 * <P CLASS="textintable" ALIGN=LEFT>
336
 * 518
337
 * </P>
338
 * </TD>
339
 * <TD WIDTH=118 BGCOLOR="#ffffff">
340
 * <P CLASS="textintable" ALIGN=LEFT>
341
 * Internal syntax error
342
 * </P>
343
 * </TD>
344
 * <TD WIDTH=401 BGCOLOR="#ffffff">
345
 * <P CLASS="textintable" ALIGN=LEFT>
346
 * Variable is not available
347
 * </P>
348
 * </TD>
349
 * </TR>
350
 * <TR VALIGN=TOP>
351
 * <TD WIDTH=42 BGCOLOR="#ffffff">
352
 * <P CLASS="textintable" ALIGN=LEFT>
353
 * 519
354
 * </P>
355
 * </TD>
356
 * <TD WIDTH=118 BGCOLOR="#ffffff">
357
 * <P CLASS="textintable" ALIGN=LEFT>
358
 * No result (#VALUE is in the cell rather than Err:519!)
359
 * </P>
360
 * </TD>
361
 * <TD WIDTH=401 BGCOLOR="#ffffff">
362
 * <P CLASS="textintable" ALIGN=LEFT>
363
 * Formula yields a value that does not corresponds to the definition, or a cell
364
 * that is referenced in the formula contains text instead of a number.
365
 * </P>
366
 * </TD>
367
 * </TR>
368
 * <TR VALIGN=TOP>
369
 * <TD WIDTH=42 BGCOLOR="#ffffff">
370
 * <P CLASS="textintable" ALIGN=LEFT>
371
 * 520
372
 * </P>
373
 * </TD>
374
 * <TD WIDTH=118 BGCOLOR="#ffffff">
375
 * <P CLASS="textintable" ALIGN=LEFT>
376
 * Internal syntax error
377
 * </P>
378
 * </TD>
379
 * <TD WIDTH=401 BGCOLOR="#ffffff">
380
 * <P CLASS="textintable" ALIGN=LEFT>
381
 * Compiler creates an unknown compiler code.
382
 * </P>
383
 * </TD>
384
 * </TR>
385
 * <TR VALIGN=TOP>
386
 * <TD WIDTH=42 BGCOLOR="#ffffff">
387
 * <P CLASS="textintable" ALIGN=LEFT>
388
 * 521
389
 * </P>
390
 * </TD>
391
 * <TD WIDTH=118 BGCOLOR="#ffffff">
392
 * <P CLASS="textintable" ALIGN=LEFT>
393
 * Internal syntax error
394
 * </P>
395
 * </TD>
396
 * <TD WIDTH=401 BGCOLOR="#ffffff">
397
 * <P CLASS="textintable" ALIGN=LEFT>
398
 * No result.
399
 * </P>
400
 * </TD>
401
 * </TR>
402
 * <TR VALIGN=TOP>
403
 * <TD WIDTH=42 BGCOLOR="#ffffff">
404
 * <P CLASS="textintable" ALIGN=LEFT>
405
 * 522
406
 * </P>
407
 * </TD>
408
 * <TD WIDTH=118 BGCOLOR="#ffffff">
409
 * <P CLASS="textintable" ALIGN=LEFT>
410
 * Circular reference
411
 * </P>
412
 * </TD>
413
 * <TD WIDTH=401 BGCOLOR="#ffffff">
414
 * <P CLASS="textintable" ALIGN=LEFT>
415
 * Formula refers directly or indirectly to itself and the iterations option is
416
 * not selected under Tools - Options - Table Document - Calculate.
417
 * </P>
418
 * </TD>
419
 * </TR>
420
 * <TR VALIGN=TOP>
421
 * <TD WIDTH=42 BGCOLOR="#ffffff">
422
 * <P CLASS="textintable" ALIGN=LEFT>
423
 * 523
424
 * </P>
425
 * </TD>
426
 * <TD WIDTH=118 BGCOLOR="#ffffff">
427
 * <P CLASS="textintable" ALIGN=LEFT>
428
 * The calculation procedure does not converge
429
 * </P>
430
 * </TD>
431
 * <TD WIDTH=401 BGCOLOR="#ffffff">
432
 * <P CLASS="textintable" ALIGN=LEFT>
433
 * Financial statistics function missed a targeted value or iterations of
434
 * circular references do not reach the minimum change within the maximum steps
435
 * that are set.
436
 * </P>
437
 * </TD>
438
 * </TR>
439
 * <TR VALIGN=TOP>
440
 * <TD WIDTH=42 BGCOLOR="#ffffff">
441
 * <P CLASS="textintable" ALIGN=LEFT>
442
 * 524
443
 * </P>
444
 * </TD>
445
 * <TD WIDTH=118 BGCOLOR="#ffffff">
446
 * <P CLASS="textintable" ALIGN=LEFT>
447
 * <A NAME="kw66944_5"> </A><A NAME="kw66944_4"> </A> invalid references
448
 * (instead of Err:524 cell contains #REF)
449
 * </P>
450
 * </TD>
451
 * <TD WIDTH=401 BGCOLOR="#ffffff">
452
 * <P CLASS="textintable" ALIGN=LEFT>
453
 * <B>Compiler: </B> a column or row description name could not be resolved.
454
 * <B>Interpreter: </B> in a formula, the column, row, or sheet that contains a
455
 * referenced cell is missing.
456
 * </P>
457
 * </TD>
458
 * </TR>
459
 * <TR VALIGN=TOP>
460
 * <TD WIDTH=42 BGCOLOR="#ffffff">
461
 * <P CLASS="textintable" ALIGN=LEFT>
462
 * 525
463
 * </P>
464
 * </TD>
465
 * <TD WIDTH=118 BGCOLOR="#ffffff">
466
 * <P CLASS="textintable" ALIGN=LEFT>
467
 * <A NAME="kw66944_3"> </A><A NAME="kw66944_2"> </A> invalid names (instead of
468
 * Err:525 cell contains #NAME?)
469
 * </P>
470
 * </TD>
471
 * <TD WIDTH=401 BGCOLOR="#ffffff">
472
 * <P CLASS="textintable" ALIGN=LEFT>
473
 * An identifier could not be evaluated, for example, no valid reference, no
474
 * valid domain name, no column/row label, no macro, incorrect decimal divider,
475
 * add-in not found.
476
 * </P>
477
 * </TD>
478
 * </TR>
479
 * <TR VALIGN=TOP>
480
 * <TD WIDTH=42 BGCOLOR="#ffffff">
481
 * <P CLASS="textintable" ALIGN=LEFT>
482
 * 526
483
 * </P>
484
 * </TD>
485
 * <TD WIDTH=118 BGCOLOR="#ffffff">
486
 * <P CLASS="textintable" ALIGN=LEFT>
487
 * Internal syntax error
488
 * </P>
489
 * </TD>
490
 * <TD WIDTH=401 BGCOLOR="#ffffff">
491
 * <P CLASS="textintable" ALIGN=LEFT>
492
 * Obsolete, no longer used, but could come from old documents if the result is
493
 * a formula from a domain.
494
 * </P>
495
 * </TD>
496
 * </TR>
497
 * <TR VALIGN=TOP>
498
 * <TD WIDTH=42 BGCOLOR="#ffffff">
499
 * <P CLASS="textintable" ALIGN=LEFT>
500
 * 527
501
 * </P>
502
 * </TD>
503
 * <TD WIDTH=118 BGCOLOR="#ffffff">
504
 * <P CLASS="textintable" ALIGN=LEFT>
505
 * Internal overflow
506
 * </P>
507
 * </TD>
508
 * <TD WIDTH=401 BGCOLOR="#ffffff">
509
 * <P CLASS="textintable" ALIGN=LEFT>
510
 * <B>Interpreter: </B>References, such as when a cell references a cell, are
511
 * too encapsulated.
512
 * </P>
513
 * </TD>
514
 * </TR>
515
 * </TABLE>
516
 *  
517
 */
518
public class ErrorEval implements ValueEval {
519
520
    private int errorCode;
521
522
    // Oo std error codes
523
    public static final ErrorEval ERROR_501 = new ErrorEval(501);
524
525
    public static final ErrorEval ERROR_502 = new ErrorEval(502);
526
527
    public static final ErrorEval ERROR_503 = new ErrorEval(503);
528
529
    public static final ErrorEval ERROR_504 = new ErrorEval(504);
530
531
    public static final ErrorEval ERROR_505 = new ErrorEval(505);
532
533
    public static final ErrorEval ERROR_506 = new ErrorEval(506);
534
535
    public static final ErrorEval ERROR_507 = new ErrorEval(507);
536
537
    public static final ErrorEval ERROR_508 = new ErrorEval(508);
538
539
    public static final ErrorEval ERROR_509 = new ErrorEval(509);
540
541
    public static final ErrorEval ERROR_510 = new ErrorEval(510);
542
543
    public static final ErrorEval ERROR_511 = new ErrorEval(511);
544
545
    public static final ErrorEval ERROR_512 = new ErrorEval(512);
546
547
    public static final ErrorEval ERROR_513 = new ErrorEval(513);
548
549
    public static final ErrorEval ERROR_514 = new ErrorEval(514);
550
551
    public static final ErrorEval ERROR_515 = new ErrorEval(515);
552
553
    public static final ErrorEval ERROR_516 = new ErrorEval(516);
554
555
    public static final ErrorEval ERROR_517 = new ErrorEval(517);
556
557
    public static final ErrorEval ERROR_518 = new ErrorEval(518);
558
559
    public static final ErrorEval ERROR_519 = new ErrorEval(519);
560
561
    public static final ErrorEval ERROR_520 = new ErrorEval(520);
562
563
    public static final ErrorEval ERROR_521 = new ErrorEval(521);
564
565
    public static final ErrorEval ERROR_522 = new ErrorEval(522);
566
567
    public static final ErrorEval ERROR_523 = new ErrorEval(523);
568
569
    public static final ErrorEval ERROR_524 = new ErrorEval(524);
570
571
    public static final ErrorEval ERROR_525 = new ErrorEval(525);
572
573
    public static final ErrorEval ERROR_526 = new ErrorEval(526);
574
575
    public static final ErrorEval ERROR_527 = new ErrorEval(527);
576
577
    public static final ErrorEval NAME_INVALID = ERROR_525;
578
579
    public static final ErrorEval VALUE_INVALID = ERROR_519;
580
581
    
582
    // Non std error codes
583
    public static final ErrorEval UNKNOWN_ERROR = new ErrorEval(-20);
584
585
    public static final ErrorEval FUNCTION_NOT_IMPLEMENTED = new ErrorEval(-30);
586
587
    public static final ErrorEval REF_INVALID = new ErrorEval(-40);
588
589
    public static final ErrorEval NA = new ErrorEval(-50);
590
    
591
    public static final ErrorEval CIRCULAR_REF_ERROR = new ErrorEval(-60);
592
    
593
    public static final ErrorEval DIV_ZERO = new ErrorEval(-70);
594
    
595
    public static final ErrorEval NUM_ERROR = new ErrorEval(-80);
596
597
    private ErrorEval(int errorCode) {
598
        this.errorCode = errorCode;
599
    }
600
601
    public int getErrorCode() {
602
        return errorCode;
603
    }
604
605
    public String getStringValue() {
606
        return "Err:" + Integer.toString(errorCode);
607
    }
608
609
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Eval.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 Eval {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FuncVarEval.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.AbstractFunctionPtg;
8
import org.apache.poi.hssf.record.formula.Ptg;
9
import org.apache.poi.hssf.record.formula.functions.Function;
10
11
/**
12
 * @author Amol S. Deshmukh &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
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
24
        Eval retval = null;
25
        Function f = getFunction();
26
        if (f != null)
27
            retval = f.evaluate(operands, srcRow, srcCol);
28
        else
29
            retval = ErrorEval.FUNCTION_NOT_IMPLEMENTED;
30
        return retval;
31
    }
32
33
    public int getNumberOfOperands() {
34
        return delegate.getNumberOfOperands();
35
    }
36
37
    public int getType() {
38
        return delegate.getType();
39
    }
40
41
    public short getFunctionIndex() {
42
        return delegate.getFunctionIndex();
43
    }
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java (+379 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
16
    public Function getFunction() {
17
        short fidx = getFunctionIndex();
18
        return functions[fidx];
19
    }
20
21
    public abstract short getFunctionIndex();
22
23
    private static Function[] produceFunctions() {
24
        Function[] retval = new Function[368];
25
        retval[0] = new Count(); // COUNT
26
        retval[1] = null; // Specialflag(); // SPECIALFLAG
27
        retval[2] = new IsNa(); // ISNA
28
        retval[3] = new IsError(); // ISERROR
29
        retval[4] = new Sum(); // SUM
30
        retval[5] = new Average(); // AVERAGE
31
        retval[6] = new Min(); // MIN
32
        retval[7] = new Max(); // MAX
33
        retval[8] = new Row(); // ROW
34
        retval[9] = new Column(); // COLUMN
35
        retval[10] = new Na(); // NA
36
        retval[11] = new Npv(); // NPV
37
        retval[12] = new Stdev(); // STDEV
38
        retval[13] = new Dollar(); // DOLLAR
39
        retval[14] = new Fixed(); // FIXED
40
        retval[15] = new Sin(); // SIN
41
        retval[16] = new Cos(); // COS
42
        retval[17] = new Tan(); // TAN
43
        retval[18] = new Atan(); // ATAN
44
        retval[19] = new Pi(); // PI
45
        retval[20] = new Sqrt(); // SQRT
46
        retval[21] = new Exp(); // EXP
47
        retval[22] = new Ln(); // LN
48
        retval[23] = new Log10(); // LOG10
49
        retval[24] = new Abs(); // ABS
50
        retval[25] = new Int(); // INT
51
        retval[26] = new Sign(); // SIGN
52
        retval[27] = new Round(); // ROUND
53
        retval[28] = new Lookup(); // LOOKUP
54
        retval[29] = new Index(); // INDEX
55
        retval[30] = new Rept(); // REPT
56
        retval[31] = new Mid(); // MID
57
        retval[32] = new Len(); // LEN
58
        retval[33] = new Value(); // VALUE
59
        retval[34] = new True(); // TRUE
60
        retval[35] = new False(); // FALSE
61
        retval[36] = new And(); // AND
62
        retval[37] = new Or(); // OR
63
        retval[38] = new Not(); // NOT
64
        retval[39] = new Mod(); // MOD
65
        retval[40] = new Dcount(); // DCOUNT
66
        retval[41] = new Dsum(); // DSUM
67
        retval[42] = new Daverage(); // DAVERAGE
68
        retval[43] = new Dmin(); // DMIN
69
        retval[44] = new Dmax(); // DMAX
70
        retval[45] = new Dstdev(); // DSTDEV
71
        retval[46] = new Var(); // VAR
72
        retval[47] = new Dvar(); // DVAR
73
        retval[48] = new Text(); // TEXT
74
        retval[49] = new Linest(); // LINEST
75
        retval[50] = new Trend(); // TREND
76
        retval[51] = new Logest(); // LOGEST
77
        retval[52] = new Growth(); // GROWTH
78
        retval[53] = new Goto(); // GOTO
79
        retval[54] = new Halt(); // HALT
80
        retval[56] = new Pv(); // PV
81
        retval[57] = new Fv(); // FV
82
        retval[58] = new Nper(); // NPER
83
        retval[59] = new Pmt(); // PMT
84
        retval[60] = new Rate(); // RATE
85
        retval[61] = new Mirr(); // MIRR
86
        retval[62] = new Irr(); // IRR
87
        retval[63] = new Rand(); // RAND
88
        retval[64] = new Match(); // MATCH
89
        retval[65] = new Date(); // DATE
90
        retval[66] = new Time(); // TIME
91
        retval[67] = new Day(); // DAY
92
        retval[68] = new Month(); // MONTH
93
        retval[69] = new Year(); // YEAR
94
        retval[70] = new Weekday(); // WEEKDAY
95
        retval[71] = new Hour(); // HOUR
96
        retval[72] = new Minute(); // MINUTE
97
        retval[73] = new Second(); // SECOND
98
        retval[74] = new Now(); // NOW
99
        retval[75] = new Areas(); // AREAS
100
        retval[76] = new Rows(); // ROWS
101
        retval[77] = new Columns(); // COLUMNS
102
        retval[78] = new Offset(); // OFFSET
103
        retval[79] = new Absref(); // ABSREF
104
        retval[80] = new Relref(); // RELREF
105
        retval[81] = new Argument(); // ARGUMENT
106
        retval[82] = new Search(); // SEARCH
107
        retval[83] = new Transpose(); // TRANSPOSE
108
        retval[84] = new org.apache.poi.hssf.record.formula.functions.Error(); // ERROR
109
        retval[85] = new Step(); // STEP
110
        retval[86] = new Type(); // TYPE
111
        retval[87] = new Echo(); // ECHO
112
        retval[88] = new Setname(); // SETNAME
113
        retval[89] = new Caller(); // CALLER
114
        retval[90] = new Deref(); // DEREF
115
        retval[91] = new Windows(); // WINDOWS
116
        retval[92] = new Series(); // SERIES
117
        retval[93] = new Documents(); // DOCUMENTS
118
        retval[94] = new Activecell(); // ACTIVECELL
119
        retval[95] = new Selection(); // SELECTION
120
        retval[96] = new Result(); // RESULT
121
        retval[97] = new Atan2(); // ATAN2
122
        retval[98] = new Asin(); // ASIN
123
        retval[99] = new Acos(); // ACOS
124
        retval[100] = new Choose(); // CHOOSE
125
        retval[101] = new Hlookup(); // HLOOKUP
126
        retval[102] = new Vlookup(); // VLOOKUP
127
        retval[103] = new Links(); // LINKS
128
        retval[104] = new Input(); // INPUT
129
        retval[105] = new Isref(); // ISREF
130
        retval[106] = new Getformula(); // GETFORMULA
131
        retval[107] = new Getname(); // GETNAME
132
        retval[108] = new Setvalue(); // SETVALUE
133
        retval[109] = new Log(); // LOG
134
        retval[110] = new Exec(); // EXEC
135
        retval[111] = new Char(); // CHAR
136
        retval[112] = new Lower(); // LOWER
137
        retval[113] = new Upper(); // UPPER
138
        retval[114] = new Proper(); // PROPER
139
        retval[115] = new Left(); // LEFT
140
        retval[116] = new Right(); // RIGHT
141
        retval[117] = new Exact(); // EXACT
142
        retval[118] = new Trim(); // TRIM
143
        retval[119] = new Replace(); // REPLACE
144
        retval[120] = new Substitute(); // SUBSTITUTE
145
        retval[121] = new Code(); // CODE
146
        retval[122] = new Names(); // NAMES
147
        retval[123] = new Directory(); // DIRECTORY
148
        retval[124] = new Find(); // FIND
149
        retval[125] = new Cell(); // CELL
150
        retval[126] = new Iserr(); // ISERR
151
        retval[127] = new Istext(); // ISTEXT
152
        retval[128] = new Isnumber(); // ISNUMBER
153
        retval[129] = new Isblank(); // ISBLANK
154
        retval[130] = new T(); // T
155
        retval[131] = new N(); // N
156
        retval[132] = new Fopen(); // FOPEN
157
        retval[133] = new Fclose(); // FCLOSE
158
        retval[134] = new Fsize(); // FSIZE
159
        retval[135] = new Freadln(); // FREADLN
160
        retval[136] = new Fread(); // FREAD
161
        retval[137] = new Fwriteln(); // FWRITELN
162
        retval[138] = new Fwrite(); // FWRITE
163
        retval[139] = new Fpos(); // FPOS
164
        retval[140] = new Datevalue(); // DATEVALUE
165
        retval[141] = new Timevalue(); // TIMEVALUE
166
        retval[142] = new Sln(); // SLN
167
        retval[143] = new Syd(); // SYD
168
        retval[144] = new Ddb(); // DDB
169
        retval[145] = new Getdef(); // GETDEF
170
        retval[146] = new Reftext(); // REFTEXT
171
        retval[147] = new Textref(); // TEXTREF
172
        retval[148] = new Indirect(); // INDIRECT
173
        retval[149] = new Register(); // REGISTER
174
        retval[150] = new Call(); // CALL
175
        retval[151] = new Addbar(); // ADDBAR
176
        retval[152] = new Addmenu(); // ADDMENU
177
        retval[153] = new Addcommand(); // ADDCOMMAND
178
        retval[154] = new Enablecommand(); // ENABLECOMMAND
179
        retval[155] = new Checkcommand(); // CHECKCOMMAND
180
        retval[156] = new Renamecommand(); // RENAMECOMMAND
181
        retval[157] = new Showbar(); // SHOWBAR
182
        retval[158] = new Deletemenu(); // DELETEMENU
183
        retval[159] = new Deletecommand(); // DELETECOMMAND
184
        retval[160] = new Getchartitem(); // GETCHARTITEM
185
        retval[161] = new Dialogbox(); // DIALOGBOX
186
        retval[162] = new Clean(); // CLEAN
187
        retval[163] = new Mdeterm(); // MDETERM
188
        retval[164] = new Minverse(); // MINVERSE
189
        retval[165] = new Mmult(); // MMULT
190
        retval[166] = new Files(); // FILES
191
        retval[167] = new Ipmt(); // IPMT
192
        retval[168] = new Ppmt(); // PPMT
193
        retval[169] = new Counta(); // COUNTA
194
        retval[170] = new Cancelkey(); // CANCELKEY
195
        retval[175] = new Initiate(); // INITIATE
196
        retval[176] = new Request(); // REQUEST
197
        retval[177] = new Poke(); // POKE
198
        retval[178] = new Execute(); // EXECUTE
199
        retval[179] = new Terminate(); // TERMINATE
200
        retval[180] = new Restart(); // RESTART
201
        retval[181] = new Help(); // HELP
202
        retval[182] = new Getbar(); // GETBAR
203
        retval[183] = new Product(); // PRODUCT
204
        retval[184] = new Fact(); // FACT
205
        retval[185] = new Getcell(); // GETCELL
206
        retval[186] = new Getworkspace(); // GETWORKSPACE
207
        retval[187] = new Getwindow(); // GETWINDOW
208
        retval[188] = new Getdocument(); // GETDOCUMENT
209
        retval[189] = new Dproduct(); // DPRODUCT
210
        retval[190] = new Isnontext(); // ISNONTEXT
211
        retval[191] = new Getnote(); // GETNOTE
212
        retval[192] = new Note(); // NOTE
213
        retval[193] = new Stdevp(); // STDEVP
214
        retval[194] = new Varp(); // VARP
215
        retval[195] = new Dstdevp(); // DSTDEVP
216
        retval[196] = new Dvarp(); // DVARP
217
        retval[197] = new Trunc(); // TRUNC
218
        retval[198] = new Islogical(); // ISLOGICAL
219
        retval[199] = new Dcounta(); // DCOUNTA
220
        retval[200] = new Deletebar(); // DELETEBAR
221
        retval[201] = new Unregister(); // UNREGISTER
222
        retval[204] = new Usdollar(); // USDOLLAR
223
        retval[205] = new Findb(); // FINDB
224
        retval[206] = new Searchb(); // SEARCHB
225
        retval[207] = new Replaceb(); // REPLACEB
226
        retval[208] = new Leftb(); // LEFTB
227
        retval[209] = new Rightb(); // RIGHTB
228
        retval[210] = new Midb(); // MIDB
229
        retval[211] = new Lenb(); // LENB
230
        retval[212] = new Roundup(); // ROUNDUP
231
        retval[213] = new Rounddown(); // ROUNDDOWN
232
        retval[214] = new Asc(); // ASC
233
        retval[215] = new Dbcs(); // DBCS
234
        retval[216] = new Rank(); // RANK
235
        retval[219] = new Address(); // ADDRESS
236
        retval[220] = new Days360(); // DAYS360
237
        retval[221] = new Today(); // TODAY
238
        retval[222] = new Vdb(); // VDB
239
        retval[227] = new Median(); // MEDIAN
240
        retval[228] = new Sumproduct(); // SUMPRODUCT
241
        retval[229] = new Sinh(); // SINH
242
        retval[230] = new Cosh(); // COSH
243
        retval[231] = new Tanh(); // TANH
244
        retval[232] = new Asinh(); // ASINH
245
        retval[233] = new Acosh(); // ACOSH
246
        retval[234] = new Atanh(); // ATANH
247
        retval[235] = new Dget(); // DGET
248
        retval[236] = new Createobject(); // CREATEOBJECT
249
        retval[237] = new Volatile(); // VOLATILE
250
        retval[238] = new Lasterror(); // LASTERROR
251
        retval[239] = new Customundo(); // CUSTOMUNDO
252
        retval[240] = new Customrepeat(); // CUSTOMREPEAT
253
        retval[241] = new Formulaconvert(); // FORMULACONVERT
254
        retval[242] = new Getlinkinfo(); // GETLINKINFO
255
        retval[243] = new Textbox(); // TEXTBOX
256
        retval[244] = new Info(); // INFO
257
        retval[245] = new Group(); // GROUP
258
        retval[246] = new Getobject(); // GETOBJECT
259
        retval[247] = new Db(); // DB
260
        retval[248] = new Pause(); // PAUSE
261
        retval[250] = new Resume(); // RESUME
262
        retval[252] = new Frequency(); // FREQUENCY
263
        retval[253] = new Addtoolbar(); // ADDTOOLBAR
264
        retval[254] = new Deletetoolbar(); // DELETETOOLBAR
265
        retval[255] = new Externalflag(); // EXTERNALFLAG
266
        retval[256] = new Resettoolbar(); // RESETTOOLBAR
267
        retval[257] = new Evaluate(); // EVALUATE
268
        retval[258] = new Gettoolbar(); // GETTOOLBAR
269
        retval[259] = new Gettool(); // GETTOOL
270
        retval[260] = new Spellingcheck(); // SPELLINGCHECK
271
        retval[261] = new Errortype(); // ERRORTYPE
272
        retval[262] = new Apptitle(); // APPTITLE
273
        retval[263] = new Windowtitle(); // WINDOWTITLE
274
        retval[264] = new Savetoolbar(); // SAVETOOLBAR
275
        retval[265] = new Enabletool(); // ENABLETOOL
276
        retval[266] = new Presstool(); // PRESSTOOL
277
        retval[267] = new Registerid(); // REGISTERID
278
        retval[268] = new Getworkbook(); // GETWORKBOOK
279
        retval[269] = new Avedev(); // AVEDEV
280
        retval[270] = new Betadist(); // BETADIST
281
        retval[271] = new Gammaln(); // GAMMALN
282
        retval[272] = new Betainv(); // BETAINV
283
        retval[273] = new Binomdist(); // BINOMDIST
284
        retval[274] = new Chidist(); // CHIDIST
285
        retval[275] = new Chiinv(); // CHIINV
286
        retval[276] = new Combin(); // COMBIN
287
        retval[277] = new Confidence(); // CONFIDENCE
288
        retval[278] = new Critbinom(); // CRITBINOM
289
        retval[279] = new Even(); // EVEN
290
        retval[280] = new Expondist(); // EXPONDIST
291
        retval[281] = new Fdist(); // FDIST
292
        retval[282] = new Finv(); // FINV
293
        retval[283] = new Fisher(); // FISHER
294
        retval[284] = new Fisherinv(); // FISHERINV
295
        retval[285] = new Floor(); // FLOOR
296
        retval[286] = new Gammadist(); // GAMMADIST
297
        retval[287] = new Gammainv(); // GAMMAINV
298
        retval[288] = new Ceiling(); // CEILING
299
        retval[289] = new Hypgeomdist(); // HYPGEOMDIST
300
        retval[290] = new Lognormdist(); // LOGNORMDIST
301
        retval[291] = new Loginv(); // LOGINV
302
        retval[292] = new Negbinomdist(); // NEGBINOMDIST
303
        retval[293] = new Normdist(); // NORMDIST
304
        retval[294] = new Normsdist(); // NORMSDIST
305
        retval[295] = new Norminv(); // NORMINV
306
        retval[296] = new Normsinv(); // NORMSINV
307
        retval[297] = new Standardize(); // STANDARDIZE
308
        retval[298] = new Odd(); // ODD
309
        retval[299] = new Permut(); // PERMUT
310
        retval[300] = new Poisson(); // POISSON
311
        retval[301] = new Tdist(); // TDIST
312
        retval[302] = new Weibull(); // WEIBULL
313
        retval[303] = new Sumxmy2(); // SUMXMY2
314
        retval[304] = new Sumx2my2(); // SUMX2MY2
315
        retval[305] = new Sumx2py2(); // SUMX2PY2
316
        retval[306] = new Chitest(); // CHITEST
317
        retval[307] = new Correl(); // CORREL
318
        retval[308] = new Covar(); // COVAR
319
        retval[309] = new Forecast(); // FORECAST
320
        retval[310] = new Ftest(); // FTEST
321
        retval[311] = new Intercept(); // INTERCEPT
322
        retval[312] = new Pearson(); // PEARSON
323
        retval[313] = new Rsq(); // RSQ
324
        retval[314] = new Steyx(); // STEYX
325
        retval[315] = new Slope(); // SLOPE
326
        retval[316] = new Ttest(); // TTEST
327
        retval[317] = new Prob(); // PROB
328
        retval[318] = new Devsq(); // DEVSQ
329
        retval[319] = new Geomean(); // GEOMEAN
330
        retval[320] = new Harmean(); // HARMEAN
331
        retval[321] = new Sumsq(); // SUMSQ
332
        retval[322] = new Kurt(); // KURT
333
        retval[323] = new Skew(); // SKEW
334
        retval[324] = new Ztest(); // ZTEST
335
        retval[325] = new Large(); // LARGE
336
        retval[326] = new Small(); // SMALL
337
        retval[327] = new Quartile(); // QUARTILE
338
        retval[328] = new Percentile(); // PERCENTILE
339
        retval[329] = new Percentrank(); // PERCENTRANK
340
        retval[330] = new Mode(); // MODE
341
        retval[331] = new Trimmean(); // TRIMMEAN
342
        retval[332] = new Tinv(); // TINV
343
        retval[334] = new Moviecommand(); // MOVIECOMMAND
344
        retval[335] = new Getmovie(); // GETMOVIE
345
        retval[336] = new Concatenate(); // CONCATENATE
346
        retval[337] = new Power(); // POWER
347
        retval[338] = new Pivotadddata(); // PIVOTADDDATA
348
        retval[339] = new Getpivottable(); // GETPIVOTTABLE
349
        retval[340] = new Getpivotfield(); // GETPIVOTFIELD
350
        retval[341] = new Getpivotitem(); // GETPIVOTITEM
351
        retval[342] = new Radians(); // RADIANS
352
        retval[343] = new Degrees(); // DEGREES
353
        retval[344] = new Subtotal(); // SUBTOTAL
354
        retval[345] = new Sumif(); // SUMIF
355
        retval[346] = new Countif(); // COUNTIF
356
        retval[347] = new Countblank(); // COUNTBLANK
357
        retval[348] = new Scenarioget(); // SCENARIOGET
358
        retval[349] = new Optionslistsget(); // OPTIONSLISTSGET
359
        retval[350] = new Ispmt(); // ISPMT
360
        retval[351] = new Datedif(); // DATEDIF
361
        retval[352] = new Datestring(); // DATESTRING
362
        retval[353] = new Numberstring(); // NUMBERSTRING
363
        retval[354] = new Roman(); // ROMAN
364
        retval[355] = new Opendialog(); // OPENDIALOG
365
        retval[356] = new Savedialog(); // SAVEDIALOG
366
        retval[357] = new Viewget(); // VIEWGET
367
        retval[358] = new Getpivotdata(); // GETPIVOTDATA
368
        retval[359] = new Hyperlink(); // HYPERLINK
369
        retval[360] = new Phonetic(); // PHONETIC
370
        retval[361] = new Averagea(); // AVERAGEA
371
        retval[362] = new Maxa(); // MAXA
372
        retval[363] = new Mina(); // MINA
373
        retval[364] = new Stdevpa(); // STDEVPA
374
        retval[365] = new Varpa(); // VARPA
375
        retval[366] = new Stdeva(); // STDEVA
376
        retval[367] = new Vara(); // VARA
377
        return retval;
378
    }
379
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java (+51 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 extends RelationalOperationEval {
15
16
    private GreaterEqualPtg delegate;
17
18
    public GreaterEqualEval(Ptg ptg) {
19
        this.delegate = (GreaterEqualPtg) ptg;
20
    }
21
22
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
23
        ValueEval retval = null;
24
        
25
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
26
        retval = rvs.ee;
27
        int result = 0;
28
        if (retval == null) {
29
            result = doComparison(rvs.bs);
30
            if (result == 0) {
31
                result = doComparison(rvs.ss);
32
            }
33
            if (result == 0) {
34
                result = doComparison(rvs.ds);
35
            }
36
37
            retval = (result >= 0) ? BoolEval.TRUE : BoolEval.FALSE;
38
        }
39
40
        return retval;
41
    }
42
43
    public int getNumberOfOperands() {
44
        return delegate.getNumberOfOperands();
45
    }
46
47
    public int getType() {
48
        return delegate.getType();
49
    }
50
51
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java (+51 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 extends RelationalOperationEval {
15
16
    private GreaterThanPtg delegate;
17
18
    public GreaterThanEval(Ptg ptg) {
19
        this.delegate = (GreaterThanPtg) ptg;
20
    }
21
22
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
23
        ValueEval retval = null;
24
        
25
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
26
        retval = rvs.ee;
27
        int result = 0;
28
        if (retval == null) {
29
            result = doComparison(rvs.bs);
30
            if (result == 0) {
31
                result = doComparison(rvs.ss);
32
            }
33
            if (result == 0) {
34
                result = doComparison(rvs.ds);
35
            }
36
37
            retval = (result > 0) ? BoolEval.TRUE : BoolEval.FALSE;;
38
        }
39
40
        return retval;
41
    }
42
43
    public int getNumberOfOperands() {
44
        return delegate.getNumberOfOperands();
45
    }
46
47
    public int getType() {
48
        return delegate.getType();
49
    }
50
51
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java (+51 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 extends RelationalOperationEval {
15
16
    private LessEqualPtg delegate;
17
18
    public LessEqualEval(Ptg ptg) {
19
        this.delegate = (LessEqualPtg) ptg;
20
    }
21
22
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
23
        ValueEval retval = null;
24
        
25
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
26
        retval = rvs.ee;
27
        int result = 0;
28
        if (retval == null) {
29
            result = doComparison(rvs.bs);
30
            if (result == 0) {
31
                result = doComparison(rvs.ss);
32
            }
33
            if (result == 0) {
34
                result = doComparison(rvs.ds);
35
            }
36
37
            retval = (result <= 0) ? BoolEval.TRUE : BoolEval.FALSE;;
38
        }
39
40
        return retval;
41
    }
42
43
    public int getNumberOfOperands() {
44
        return delegate.getNumberOfOperands();
45
    }
46
47
    public int getType() {
48
        return delegate.getType();
49
    }
50
51
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/LessThanEval.java (+52 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 extends RelationalOperationEval {
15
16
    private LessThanPtg delegate;
17
18
    public LessThanEval(Ptg ptg) {
19
        this.delegate = (LessThanPtg) ptg;
20
    }
21
22
23
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
24
        ValueEval retval = null;
25
        
26
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
27
        retval = rvs.ee;
28
        int result = 0;
29
        if (retval == null) {
30
            result = doComparison(rvs.bs);
31
            if (result == 0) {
32
                result = doComparison(rvs.ss);
33
            }
34
            if (result == 0) {
35
                result = doComparison(rvs.ds);
36
            }
37
38
            retval = (result < 0) ? BoolEval.TRUE : BoolEval.FALSE;;
39
        }
40
41
        return retval;
42
    }
43
44
    public int getNumberOfOperands() {
45
        return delegate.getNumberOfOperands();
46
    }
47
48
    public int getType() {
49
        return delegate.getType();
50
    }
51
52
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java (+84 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.MultiplyPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *  
13
 */
14
public class MultiplyEval extends NumericOperationEval {
15
16
    private MultiplyPtg delegate;
17
18
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
19
        new ValueEvalToNumericXlator((short)
20
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
21
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
22
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
23
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
24
                | ValueEvalToNumericXlator.STRING_IS_PARSED
25
                ));
26
27
    public MultiplyEval(Ptg ptg) {
28
        delegate = (MultiplyPtg) ptg;
29
    }
30
    
31
    protected ValueEvalToNumericXlator getXlator() {
32
        return NUM_XLATOR;
33
    }
34
35
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
36
        Eval retval = null;
37
        double d0 = 0;
38
        double d1 = 0;
39
        switch (operands.length) {
40
        default: // will rarely happen. currently the parser itself fails.
41
            retval = ErrorEval.UNKNOWN_ERROR;
42
            break;
43
        case 2:
44
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
45
            if (ve instanceof NumericValueEval) {
46
                d0 = ((NumericValueEval) ve).getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.VALUE_INVALID;
53
            }
54
            
55
            if (retval == null) { // no error yet
56
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
57
                if (ve instanceof NumericValueEval) {
58
                    d1 = ((NumericValueEval) ve).getNumberValue();
59
                }
60
                else if (ve instanceof BlankEval) {
61
                    // do nothing
62
                }
63
                else {
64
                    retval = ErrorEval.VALUE_INVALID;
65
                }
66
            }
67
        } // end switch
68
69
        if (retval == null) {
70
            retval = (Double.isNaN(d0) || Double.isNaN(d1)) 
71
                    ? (ValueEval) ErrorEval.VALUE_INVALID 
72
                    : new NumberEval(d0 * d1);
73
        }
74
        return retval;
75
    }
76
77
    public int getNumberOfOperands() {
78
        return delegate.getNumberOfOperands();
79
    }
80
81
    public int getType() {
82
        return delegate.getType();
83
    }
84
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java (+52 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 extends RelationalOperationEval {
15
16
    private NotEqualPtg delegate;
17
18
    public NotEqualEval(Ptg ptg) {
19
        this.delegate = (NotEqualPtg) ptg;
20
    }
21
22
23
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
24
        ValueEval retval = null;
25
        
26
        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
27
        retval = rvs.ee;
28
        int result = 0;
29
        if (retval == null) {
30
            result = doComparison(rvs.bs);
31
            if (result == 0) {
32
                result = doComparison(rvs.ss);
33
            }
34
            if (result == 0) {
35
                result = doComparison(rvs.ds);
36
            }
37
38
            retval = (result != 0) ? BoolEval.TRUE : BoolEval.FALSE;
39
        }
40
41
        return retval;
42
    }
43
44
    public int getNumberOfOperands() {
45
        return delegate.getNumberOfOperands();
46
    }
47
48
    public int getType() {
49
        return delegate.getType();
50
    }
51
52
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumberEval.java (+55 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
    private String stringValue;
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
    public String getStringValue() { // TODO: limit to 15 decimal places
38
        if (stringValue == null)
39
            makeString();
40
        return stringValue;
41
    }
42
    
43
    protected void makeString() {
44
        if (!Double.isNaN(value)) {
45
            long lvalue = Math.round(value);
46
            if (lvalue == value) {
47
                stringValue = String.valueOf(lvalue);
48
            }
49
            else {
50
                stringValue = String.valueOf(value);
51
            }
52
        }
53
    }
54
    
55
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/NumericOperationEval.java (+50 lines)
Added Link Here
1
/*
2
 * Created on May 14, 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 abstract class NumericOperationEval implements OperationEval {
12
13
    protected abstract ValueEvalToNumericXlator getXlator();
14
    
15
    protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
16
        ValueEval retval;
17
        if (eval instanceof AreaEval) {
18
            AreaEval ae = (AreaEval) eval;
19
            if (ae.contains(srcRow, srcCol)) { // circular ref!
20
                retval = ErrorEval.CIRCULAR_REF_ERROR;
21
            }
22
            else if (ae.isRow()) {
23
                if (ae.containsColumn(srcCol)) {
24
                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
25
                    ve = getXlator().attemptXlateToNumeric(ve);
26
                    retval = getXlator().attemptXlateToNumeric(ve);
27
                }
28
                else {
29
                    retval = ErrorEval.VALUE_INVALID;
30
                }
31
            }
32
            else if (ae.isColumn()) {
33
                if (ae.containsRow(srcRow)) {
34
                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
35
                    retval = getXlator().attemptXlateToNumeric(ve);
36
                }
37
                else {
38
                    retval = ErrorEval.VALUE_INVALID;
39
                }
40
            }
41
            else {
42
                retval = ErrorEval.VALUE_INVALID;
43
            }
44
        }
45
        else {
46
            retval = getXlator().attemptXlateToNumeric((ValueEval) eval);
47
        }
48
        return retval;
49
    }
50
}
(-)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 (+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
/**
8
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
9
 *  
10
 */
11
public interface OperationEval extends Eval {
12
13
    /*
14
     * Read this, this will make your work easier when coding 
15
     * an "evaluate()"
16
     * 
17
     * Things to note when implementing evaluate():
18
     * 1. Check the length of operands
19
     *    (use "switch(operands[x])" if possible)
20
     * 
21
     * 2. The possible Evals that you can get as args to evaluate are one of:
22
     * NumericValueEval, StringValueEval, RefEval, AreaEval
23
     * 3. If it is RefEval, the innerValueEval could be one of:
24
     * NumericValueEval, StringValueEval, BlankEval
25
     * 4. If it is AreaEval, each of the values could be one of:
26
     * NumericValueEval, StringValueEval, BlankEval, RefEval
27
     * 
28
     * 5. For numeric functions/operations, keep the result in double
29
     * till the end and before returning a new NumberEval, check to see
30
     * if the double is a NaN - if NaN, return ErrorEval.ERROR_503 
31
     */
32
    public abstract Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol);
33
34
    public abstract int getNumberOfOperands();
35
36
    public abstract int getType();
37
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/PowerEval.java (+86 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.PowerPtg;
9
10
/**
11
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
12
 *  
13
 */
14
public class PowerEval extends NumericOperationEval {
15
16
    private PowerPtg delegate;
17
18
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
19
        new ValueEvalToNumericXlator((short)
20
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
21
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
22
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
23
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
24
                | ValueEvalToNumericXlator.STRING_IS_PARSED
25
                ));
26
27
    public PowerEval(Ptg ptg) {
28
        delegate = (PowerPtg) ptg;
29
    }
30
    
31
    protected ValueEvalToNumericXlator getXlator() {
32
        return NUM_XLATOR;
33
    }
34
35
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
36
        Eval retval = null;
37
        double d0 = 0;
38
        double d1 = 0;
39
        
40
        switch (operands.length) {
41
        default: // will rarely happen. currently the parser itself fails.
42
            retval = ErrorEval.UNKNOWN_ERROR;
43
            break;
44
        case 2:
45
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
46
            if (ve instanceof NumericValueEval) {
47
                d0 = ((NumericValueEval) ve).getNumberValue();
48
            }
49
            else if (ve instanceof BlankEval) {
50
                // do nothing
51
            }
52
            else {
53
                retval = ErrorEval.VALUE_INVALID;
54
            }
55
            
56
            if (retval == null) { // no error yet
57
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
58
                if (ve instanceof NumericValueEval) {
59
                    d1 = ((NumericValueEval) ve).getNumberValue();
60
                }
61
                else if (ve instanceof BlankEval) {
62
                    // do nothing
63
                }
64
                else {
65
                    retval = ErrorEval.VALUE_INVALID;
66
                }
67
            }
68
        } // end switch
69
70
        if (retval == null) {
71
            double p = Math.pow(d0, d1);
72
            retval = (Double.isNaN(p)) 
73
                    ? (ValueEval) ErrorEval.VALUE_INVALID 
74
                    : new NumberEval(p);
75
        }
76
        return retval;
77
    }
78
79
    public int getNumberOfOperands() {
80
        return delegate.getNumberOfOperands();
81
    }
82
83
    public int getType() {
84
        return delegate.getType();
85
    }
86
}
(-)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
 */
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.ReferencePtg;
9
10
/**
11
 * @author adeshmukh
12
 *  
13
 */
14
public class Ref2DEval implements RefEval {
15
16
    private ValueEval value;
17
18
    private ReferencePtg delegate;
19
    
20
    private boolean evaluated;
21
22
    public Ref2DEval(Ptg ptg, ValueEval value, boolean evaluated) {
23
        this.value = value;
24
        this.delegate = (ReferencePtg) ptg;
25
        this.evaluated = evaluated;
26
    }
27
28
    public ValueEval getInnerValueEval() {
29
        return value;
30
    }
31
32
    public short getRow() {
33
        return delegate.getRow();
34
    }
35
36
    public short getColumn() {
37
        return delegate.getColumn();
38
    }
39
    
40
    public boolean isEvaluated() {
41
        return evaluated;
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
 */
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.Ref3DPtg;
9
10
/**
11
 * @author Amol S. Deshmukh
12
 *  
13
 */
14
public class Ref3DEval implements RefEval {
15
16
    private ValueEval value;
17
18
    private Ref3DPtg delegate;
19
20
    private boolean evaluated;
21
22
    public Ref3DEval(Ptg ptg, ValueEval value, boolean evaluated) {
23
        this.value = value;
24
        this.delegate = (Ref3DPtg) ptg;
25
        this.evaluated = evaluated;
26
    }
27
28
    public ValueEval getInnerValueEval() {
29
        return value;
30
    }
31
32
    public short getRow() {
33
        return delegate.getRow();
34
    }
35
36
    public short getColumn() {
37
        return delegate.getColumn();
38
    }
39
    
40
    public boolean isEvaluated() {
41
        return evaluated;
42
    }
43
44
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java (+57 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
 * @author Amol S Deshmukh &lt; amolweb at ya hoo dot com &gt;
10
 * 
11
 * RefEval is the super interface for Ref2D and Ref3DEval. Basically a RefEval
12
 * impl should contain reference to the original ReferencePtg or Ref3DPtg as
13
 * well as the final "value" resulting from the evaluation of the cell
14
 * reference. Thus if the HSSFCell has type CELL_TYPE_NUMERIC, the contained
15
 * value object should be of type NumberEval; if cell type is CELL_TYPE_STRING,
16
 * contained value object should be of type StringEval
17
 */
18
public interface RefEval extends ValueEval {
19
20
    /**
21
     * The (possibly evaluated) ValueEval contained
22
     * in this RefEval. eg. if cell A1 contains "test"
23
     * then in a formula referring to cell A1 
24
     * the RefEval representing
25
     * A1 will return as the getInnerValueEval() the
26
     * object of concrete type StringEval
27
     * @return
28
     */
29
    public ValueEval getInnerValueEval();
30
31
    /**
32
     * returns the column index.
33
     * @return
34
     */
35
    public short getColumn();
36
37
    /**
38
     * returns the row index.
39
     * @return
40
     */
41
    public short getRow();
42
    
43
    /**
44
     * returns true if this RefEval contains an
45
     * evaluated value instead of a direct value.
46
     * eg. say cell A1 has the value: ="test"
47
     * Then the RefEval representing A1 will return
48
     * isEvaluated() equal to false. On the other
49
     * hand, say cell A1 has the value: =B1 and
50
     * B1 has the value "test", then the RefEval
51
     * representing A1 will return isEvaluated()
52
     * equal to true.
53
     * @return
54
     */
55
    public boolean isEvaluated();
56
57
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java (+200 lines)
Added Link Here
1
/*
2
 * Created on May 10, 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 abstract class RelationalOperationEval implements OperationEval {
12
13
    protected class RelationalValues {
14
        public Double[] ds = new Double[2];
15
        public Boolean[] bs = new Boolean[2];
16
        public String[] ss = new String[3];
17
        public ErrorEval ee = null;
18
    }
19
20
    
21
    /*
22
     * This is a description of how the relational operators apply in MS Excel.
23
     * Use this as a guideline when testing/implementing the evaluate methods 
24
     * for the relational operators Evals.
25
     * 
26
     * Bool > any number. ALWAYS
27
     * Bool > any string. ALWAYS
28
     * Bool.TRUE > Bool.FALSE
29
     * 
30
     * String > any number. ALWAYS
31
     * String > Blank. ALWAYS
32
     * String are sorted dictionary wise
33
     * 
34
     * Blank == 0 (numeric)
35
     */
36
    public RelationalValues doEvaluate(Eval[] operands, int srcRow, short srcCol) {
37
        RelationalValues retval = new RelationalValues();
38
        
39
        switch (operands.length) {
40
        default:
41
            retval.ee = ErrorEval.ERROR_520;
42
            break;
43
        case 2:
44
            internalDoEvaluate(operands, srcRow, srcCol, retval, 0);
45
            internalDoEvaluate(operands, srcRow, srcCol, retval, 1);
46
        } // end switch
47
        return retval;
48
    }
49
    
50
    /**
51
     * convenience method to avoid code duplication for multiple operands
52
     * @param operands
53
     * @param srcRow
54
     * @param srcCol
55
     * @param retval
56
     * @param index
57
     */
58
    private void internalDoEvaluate(Eval[] operands, int srcRow, short srcCol, RelationalValues retval, int index) {
59
        if (operands[index] instanceof BoolEval) {
60
            BoolEval be = (BoolEval) operands[index];
61
            retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
62
        }
63
        else if (operands[index] instanceof NumericValueEval) {
64
            NumericValueEval ne = (NumericValueEval) operands[index];
65
            retval.ds[index] = new Double(ne.getNumberValue());
66
        }
67
        else if (operands[index] instanceof StringValueEval) {
68
            StringValueEval se = (StringValueEval) operands[index];
69
            retval.ss[index] = se.getStringValue();
70
        }
71
        else if (operands[index] instanceof RefEval) {
72
            RefEval re = (RefEval) operands[index];
73
            ValueEval ve = re.getInnerValueEval();
74
            if (ve instanceof BoolEval) {
75
                BoolEval be = (BoolEval) ve;
76
                retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
77
            }
78
            else if (ve instanceof BlankEval) {
79
                retval.ds[index] = new Double(0);
80
            }
81
            else if (ve instanceof NumericValueEval) {
82
                NumericValueEval ne = (NumericValueEval) ve;
83
                retval.ds[index] = new Double(ne.getNumberValue());
84
            }
85
            else if (ve instanceof StringValueEval) {
86
                StringValueEval se = (StringValueEval) ve;
87
                retval.ss[index] = se.getStringValue();
88
            }
89
        }
90
        else if (operands[index] instanceof AreaEval) {
91
            AreaEval ae = (AreaEval) operands[index];
92
            if (ae.isRow()) {
93
                if (ae.containsColumn(srcCol)) {
94
                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
95
                    if (ve instanceof BoolEval) {
96
                        BoolEval be = (BoolEval) ve;
97
                        retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
98
                    }
99
                    else if (ve instanceof BlankEval) {
100
                        retval.ds[index] = new Double(0);
101
                    }
102
                    else if (ve instanceof NumericValueEval) {
103
                        NumericValueEval ne = (NumericValueEval) ve;
104
                        retval.ds[index] = new Double(ne.getNumberValue());
105
                    }
106
                    else if (ve instanceof StringValueEval) {
107
                        StringValueEval se = (StringValueEval) ve;
108
                        retval.ss[index] = se.getStringValue();
109
                    }
110
                    else {
111
                        retval.ee = ErrorEval.VALUE_INVALID;
112
                    }
113
                }
114
                else {
115
                    retval.ee = ErrorEval.VALUE_INVALID;
116
                }
117
            }
118
            else if (ae.isColumn()) {
119
                if (ae.containsRow(srcRow)) {
120
                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
121
                    if (ve instanceof BoolEval) {
122
                        BoolEval be = (BoolEval) ve;
123
                        retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
124
                    }
125
                    else if (ve instanceof BlankEval) {
126
                        retval.ds[index] = new Double(0);
127
                    }
128
                    else if (ve instanceof NumericValueEval) {
129
                        NumericValueEval ne = (NumericValueEval) ve;
130
                        retval.ds[index] = new Double(ne.getNumberValue());
131
                    }
132
                    else if (ve instanceof StringValueEval) {
133
                        StringValueEval se = (StringValueEval) ve;
134
                        retval.ss[index] = se.getStringValue();
135
                    }
136
                    else {
137
                        retval.ee = ErrorEval.VALUE_INVALID;
138
                    }
139
                }
140
                else {
141
                    retval.ee = ErrorEval.VALUE_INVALID;
142
                }
143
            }
144
            else {
145
                retval.ee = ErrorEval.VALUE_INVALID;
146
            }
147
        }
148
    }
149
    
150
    // if both null return 0, else non null wins, else TRUE wins
151
    protected int doComparison(Boolean[] bs) {
152
        int retval = 0;
153
        if (bs[0] != null || bs[1] != null) {
154
            retval = bs[0] != null
155
                    ? bs[1] != null
156
                            ? bs[0].booleanValue()
157
                                    ? bs[1].booleanValue()
158
                                            ? 0
159
                                            : 1
160
                                    : bs[1].booleanValue()
161
                                            ? -1
162
                                            : 0
163
                            : 1
164
                    : bs[1] != null
165
                            ? -1
166
                            : 0;
167
        }
168
        return retval;
169
    }
170
171
    // if both null return 0, else non null wins, else string compare
172
    protected int doComparison(String[] ss) {
173
        int retval = 0;
174
        if (ss[0] != null || ss[1] != null) {
175
            retval = ss[0] != null
176
                    ? ss[1] != null
177
                            ? ss[0].compareTo(ss[1])
178
                            : 1
179
                    : ss[1] != null
180
                            ? -1
181
                            : 0;
182
        }
183
        return retval;
184
    }
185
186
    // if both null return 0, else non null wins, else doublevalue compare
187
    protected int doComparison(Double[] ds) {
188
        int retval = 0;
189
        if (ds[0] != null || ds[1] != null) {
190
            retval = ds[0] != null
191
                    ? ds[1] != null
192
                            ? ds[0].compareTo(ds[1])
193
                            : 1
194
                    : ds[1] != null
195
                            ? -1
196
                            : 0;
197
        }
198
        return retval;
199
    }
200
}
(-)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/StringOperationEval.java (+81 lines)
Added Link Here
1
/*
2
 * Created on May 14, 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 abstract class StringOperationEval implements OperationEval {
12
13
14
15
    /**
16
     * Returns an instanceof StringValueEval or ErrorEval or BlankEval
17
     * 
18
     * @param eval
19
     * @param srcRow
20
     * @param srcCol
21
     * @return
22
     */
23
    protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
24
        ValueEval retval;
25
        if (eval instanceof AreaEval) {
26
            AreaEval ae = (AreaEval) eval;
27
            if (ae.contains(srcRow, srcCol)) { // circular ref!
28
                retval = ErrorEval.CIRCULAR_REF_ERROR;
29
            }
30
            else if (ae.isRow()) {
31
                if (ae.containsColumn(srcCol)) {
32
                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
33
                    retval = internalResolveEval(eval);
34
                }
35
                else {
36
                    retval = ErrorEval.NAME_INVALID;
37
                }
38
            }
39
            else if (ae.isColumn()) {
40
                if (ae.containsRow(srcRow)) {
41
                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
42
                    retval = internalResolveEval(eval);
43
                }
44
                else {
45
                    retval = ErrorEval.NAME_INVALID;
46
                }
47
            }
48
            else {
49
                retval = ErrorEval.NAME_INVALID;
50
            }
51
        }
52
        else {
53
            retval = internalResolveEval(eval);
54
        }
55
        return retval;
56
    }
57
58
    private ValueEval internalResolveEval(Eval eval) {
59
        ValueEval retval;
60
        if (eval instanceof StringValueEval) {
61
            retval = (StringValueEval) eval;
62
        }
63
        else if (eval instanceof RefEval) {
64
            RefEval re = (RefEval) eval;
65
            ValueEval tve = re.getInnerValueEval();
66
            if (tve instanceof StringValueEval || tve instanceof BlankEval) {
67
                retval = tve;
68
            }
69
            else {
70
                retval = ErrorEval.NAME_INVALID;
71
            }
72
        }
73
        else if (eval instanceof BlankEval) {
74
            retval = (BlankEval) eval;
75
        }
76
        else {
77
            retval = ErrorEval.NAME_INVALID;
78
        }
79
        return retval;
80
    }
81
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/StringValueEval.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 StringValueEval extends ValueEval {
12
13
    public String getStringValue();
14
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/SubtractEval.java (+84 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 extends NumericOperationEval {
15
16
    private SubtractPtg delegate;
17
18
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
19
        new ValueEvalToNumericXlator((short)
20
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
21
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
22
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
23
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
24
                | ValueEvalToNumericXlator.STRING_IS_PARSED
25
                ));
26
27
    public SubtractEval(Ptg ptg) {
28
        delegate = (SubtractPtg) ptg;
29
    }
30
    
31
    protected ValueEvalToNumericXlator getXlator() {
32
        return NUM_XLATOR;
33
    }
34
35
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
36
        Eval retval = null;
37
        double d0 = 0;
38
        double d1 = 0;
39
        switch (operands.length) {
40
        default: // will rarely happen. currently the parser itself fails.
41
            retval = ErrorEval.UNKNOWN_ERROR;
42
            break;
43
        case 2:
44
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
45
            if (ve instanceof NumericValueEval) {
46
                d0 = ((NumericValueEval) ve).getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.VALUE_INVALID;
53
            }
54
            
55
            if (retval == null) { // no error yet
56
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
57
                if (ve instanceof NumericValueEval) {
58
                    d1 = ((NumericValueEval) ve).getNumberValue();
59
                }
60
                else if (ve instanceof BlankEval) {
61
                    // do nothing
62
                }
63
                else {
64
                    retval = ErrorEval.VALUE_INVALID;
65
                }
66
            }
67
        } // end switch
68
69
        if (retval == null) {
70
            retval = (Double.isNaN(d0) || Double.isNaN(d1)) 
71
                    ? (ValueEval) ErrorEval.VALUE_INVALID 
72
                    : new NumberEval(d0 - d1);
73
        }
74
        return retval;
75
    }
76
77
    public int getNumberOfOperands() {
78
        return delegate.getNumberOfOperands();
79
    }
80
81
    public int getType() {
82
        return delegate.getType();
83
    }
84
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java (+71 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 extends NumericOperationEval {
15
16
    private UnaryMinusPtg delegate;
17
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
18
        new ValueEvalToNumericXlator((short)
19
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
20
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
21
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
22
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
23
                | ValueEvalToNumericXlator.STRING_IS_PARSED
24
                ));
25
26
27
    public UnaryMinusEval(Ptg ptg) {
28
        this.delegate = (UnaryMinusPtg) ptg;
29
    }
30
    
31
    protected ValueEvalToNumericXlator getXlator() {
32
        return NUM_XLATOR;
33
    }
34
35
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
36
        ValueEval retval = null;
37
        double d = 0;
38
        
39
        switch (operands.length) {
40
        default:
41
            retval = ErrorEval.UNKNOWN_ERROR;
42
            break;
43
        case 1:
44
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
45
            if (ve instanceof NumericValueEval) {
46
                d = ((NumericValueEval) ve).getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else if (ve instanceof ErrorEval) {
52
                retval = ve;
53
            }
54
        }
55
        
56
        if (retval == null) {
57
            retval = new NumberEval(-d);
58
        }
59
60
        return retval;
61
    }
62
63
    public int getNumberOfOperands() {
64
        return delegate.getNumberOfOperands();
65
    }
66
67
    public int getType() {
68
        return delegate.getType();
69
    }
70
71
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java (+131 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 /*extends NumericOperationEval*/ {
15
16
    private UnaryPlusPtg delegate;
17
    
18
    /* 
19
     * COMMENT FOR COMMENTED CODE IN THIS FILE
20
     * 
21
     * The loser who programmed this in excel didnt care to
22
     * think about how strings were handled in other numeric
23
     * operations when he/she was implementing this operation :P
24
     * 
25
     * Here's what I mean:
26
     * 
27
     * Q. If the formula -"hello" evaluates to #VALUE! in excel, what should
28
     * the formula +"hello" evaluate to?
29
     * 
30
     * A. +"hello" evaluates to "hello"
31
     * 
32
     * DO NOT remove the commented code (In memory of the excel
33
     * programmer who implemented the UnaryPlus operation :)
34
     */
35
36
    
37
//    private static final ValueEvalToNumericXlator NUM_XLATOR = 
38
//        new ValueEvalToNumericXlator((short)
39
//                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
40
//                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
41
//                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
42
//                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
43
//                | ValueEvalToNumericXlator.STRING_IS_PARSED
44
//                ));
45
46
47
    public UnaryPlusEval(Ptg ptg) {
48
        this.delegate = (UnaryPlusPtg) ptg;
49
    }
50
    
51
//    protected ValueEvalToNumericXlator getXlator() {
52
//        return NUM_XLATOR;
53
//    }
54
55
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
56
        ValueEval retval = null;
57
        
58
        switch (operands.length) {
59
        default:
60
            retval = ErrorEval.UNKNOWN_ERROR;
61
            break;
62
        case 1:
63
64
//            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
65
//            if (ve instanceof NumericValueEval) {
66
//                d = ((NumericValueEval) ve).getNumberValue();
67
//            }
68
//            else if (ve instanceof BlankEval) {
69
//                // do nothing
70
//            }
71
//            else if (ve instanceof ErrorEval) {
72
//                retval = ve;
73
//            }
74
            if (operands[0] instanceof RefEval) {
75
                RefEval re = (RefEval) operands[0];
76
                retval = re.getInnerValueEval();
77
            }
78
            else if (operands[0] instanceof AreaEval) {
79
                AreaEval ae = (AreaEval) operands[0];
80
                if (ae.contains(srcRow, srcCol)) { // circular ref!
81
                    retval = ErrorEval.CIRCULAR_REF_ERROR;
82
                }
83
                else if (ae.isRow()) {
84
                    if (ae.containsColumn(srcCol)) {
85
                        ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
86
                        if (ve instanceof RefEval) {
87
                            ve = ((RefEval) ve).getInnerValueEval();
88
                        }
89
                        retval = ve;
90
                    }
91
                    else {
92
                        retval = ErrorEval.VALUE_INVALID;
93
                    }
94
                }
95
                else if (ae.isColumn()) {
96
                    if (ae.containsRow(srcRow)) {
97
                        ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
98
                        if (ve instanceof RefEval) {
99
                            ve = ((RefEval) ve).getInnerValueEval();
100
                        }
101
                        retval = ve;
102
                    }
103
                    else {
104
                        retval = ErrorEval.VALUE_INVALID;
105
                    }
106
                }
107
                else {
108
                    retval = ErrorEval.VALUE_INVALID;
109
                }
110
            }
111
            else {
112
                retval = (ValueEval) operands[0];
113
            }
114
        }
115
        
116
        if (retval instanceof BlankEval) {
117
            retval = new NumberEval(0);
118
        }
119
120
        return retval;
121
    }
122
123
    public int getNumberOfOperands() {
124
        return delegate.getNumberOfOperands();
125
    }
126
127
    public int getType() {
128
        return delegate.getType();
129
    }
130
131
}
(-)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/eval/ValueEvalToNumericXlator.java (+203 lines)
Added Link Here
1
/*
2
 * Created on May 14, 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 ValueEvalToNumericXlator {
12
13
    public static final short STRING_IS_PARSED = 0x0001;
14
    public static final short BOOL_IS_PARSED = 0x0002;
15
    
16
    public static final short REF_STRING_IS_PARSED = 0x0004;
17
    public static final short REF_BOOL_IS_PARSED = 0x0008;
18
    
19
    public static final short EVALUATED_REF_STRING_IS_PARSED = 0x0010;
20
    public static final short EVALUATED_REF_BOOL_IS_PARSED = 0x0020;
21
    
22
    public static final short STRING_TO_BOOL_IS_PARSED = 0x0040;
23
    public static final short REF_STRING_TO_BOOL_IS_PARSED = 0x0080;
24
    
25
    public static final short STRING_IS_INVALID_VALUE = 0x0100;
26
    public static final short REF_STRING_IS_INVALID_VALUE = 0x200;
27
    
28
    private final short flags;
29
    
30
    
31
    public ValueEvalToNumericXlator(short flags) {
32
        this.flags = flags;
33
    }
34
    
35
    /**
36
     * returned value can be either A NumericValueEval, BlankEval or ErrorEval.
37
     * The params can be either NumberEval, BoolEval, StringEval, or
38
     * RefEval
39
     * @param eval
40
     * @return
41
     */
42
    public ValueEval attemptXlateToNumeric(ValueEval eval) {
43
        ValueEval retval = null;
44
        
45
        if (eval == null) {
46
            retval = BlankEval.INSTANCE;
47
        }
48
        
49
        // most common case - least worries :)
50
        else if (eval instanceof NumberEval) {
51
            retval = (NumberEval) eval; 
52
        }
53
        
54
        // booleval
55
        else if (((flags | BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
56
            retval = (NumericValueEval) eval;
57
        } 
58
        
59
        // stringeval 
60
        else if (eval instanceof StringEval) {
61
            retval = handleStringEval((StringEval) eval);
62
        }
63
        
64
        // refeval
65
        else if (eval instanceof RefEval) {
66
            retval = handleRefEval((RefEval) eval);
67
        }
68
        
69
        //blankeval
70
        else if (eval instanceof BlankEval) {
71
            retval = eval;
72
        }
73
        
74
        // erroreval
75
        else if (eval instanceof ErrorEval) {
76
            retval = eval;
77
        }
78
        
79
        // probably AreaEval? then not acceptable.
80
        else {
81
            throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
82
        }
83
        return retval;
84
    }
85
    
86
    /**
87
     * uses the relevant flags to decode the supplied RefVal
88
     * @param eval
89
     * @return
90
     */
91
    private ValueEval handleRefEval(RefEval reval) {
92
        ValueEval retval = null;
93
        ValueEval eval = (ValueEval) reval.getInnerValueEval();
94
        
95
        // most common case - least worries :)
96
        if (eval instanceof NumberEval) {
97
            retval = (NumberEval) eval; // the cast is correct :)
98
        }
99
        
100
        // booleval
101
        else if (((flags | REF_BOOL_IS_PARSED) > 0) && eval instanceof BoolEval) {
102
            retval = (NumericValueEval) eval;
103
        } 
104
        
105
        // stringeval 
106
        else if (eval instanceof StringEval) {
107
            retval = handleRefStringEval((StringEval) eval);
108
        }
109
        
110
        //blankeval
111
        else if (eval instanceof BlankEval) {
112
            retval = eval;
113
        }
114
        
115
        // erroreval
116
        else if (eval instanceof ErrorEval) {
117
            retval = eval;
118
        }
119
        
120
        // probably AreaEval or another RefEval? then not acceptable.
121
        else {
122
            throw new RuntimeException("Invalid ValueEval type passed for conversion: " + eval.getClass());
123
        }
124
        return retval;
125
    }
126
    
127
    /**
128
     * uses the relevant flags to decode the StringEval
129
     * @param eval
130
     * @return
131
     */
132
    private ValueEval handleStringEval(StringEval eval) {
133
        ValueEval retval = null;
134
        if ((flags | STRING_IS_PARSED) > 0) {
135
            StringEval sve = (StringEval) eval;
136
            String s = sve.getStringValue();
137
            try { 
138
                double d = Double.parseDouble(s);
139
                retval = new NumberEval(d);
140
            } 
141
            catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
142
        }
143
        else if ((flags | STRING_TO_BOOL_IS_PARSED) > 0) {
144
            StringEval sve = (StringEval) eval;
145
            String s = sve.getStringValue();
146
            try { 
147
                boolean b = Boolean.getBoolean(s);
148
                retval = b ? BoolEval.TRUE : BoolEval.FALSE;
149
            } 
150
            catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
151
        }
152
        
153
        // strings are errors?
154
        else if ((flags | STRING_IS_INVALID_VALUE) > 0) {
155
            retval = ErrorEval.VALUE_INVALID;
156
        }
157
        
158
        // ignore strings
159
        else {
160
            retval = BlankEval.INSTANCE;
161
        }
162
        return retval;
163
    }
164
    
165
    /**
166
     * uses the relevant flags to decode the StringEval
167
     * @param eval
168
     * @return
169
     */
170
    private ValueEval handleRefStringEval(StringEval eval) {
171
        ValueEval retval = null;
172
        if ((flags | REF_STRING_IS_PARSED) > 0) {
173
            StringEval sve = (StringEval) eval;
174
            String s = sve.getStringValue();
175
            try { 
176
                double d = Double.parseDouble(s);
177
                retval = new NumberEval(d);
178
            } 
179
            catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
180
        }
181
        else if ((flags | REF_STRING_TO_BOOL_IS_PARSED) > 0) {
182
            StringEval sve = (StringEval) eval;
183
            String s = sve.getStringValue();
184
            try { 
185
                boolean b = Boolean.getBoolean(s);
186
                retval = retval = b ? BoolEval.TRUE : BoolEval.FALSE;;
187
            } 
188
            catch (Exception e) { retval = ErrorEval.VALUE_INVALID; }
189
        }
190
        
191
        // strings are errors?
192
        else if ((flags | REF_STRING_IS_INVALID_VALUE) > 0) {
193
            retval = ErrorEval.VALUE_INVALID;
194
        }
195
        
196
        // ignore strings
197
        else {
198
            retval = BlankEval.INSTANCE;
199
        }
200
        return retval;
201
    }
202
    
203
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Abs.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Abs extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            retval = ErrorEval.VALUE_INVALID;
41
            break;
42
        case 1:
43
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
44
            if (ve instanceof NumericValueEval) {
45
                NumericValueEval ne = (NumericValueEval) ve;
46
                d = ne.getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.NUM_ERROR;
53
            }
54
        }
55
        
56
        if (retval == null) {
57
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(Math.abs(d));
58
        }
59
        return retval;
60
    }
61
62
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Absref.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Absref extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acos.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Acos extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            d = Math.acos(d);
57
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
58
        }
59
        return retval;
60
    }
61
62
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Acosh.java (+60 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.ValueEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
13
14
/**
15
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
16
 * Support for hyperbolic trig functions was added as a part of 
17
 * Java distribution only in JDK1.5. This class uses custom 
18
 * naive implementation based on formulas at:
19
 * http://www.math2.org/math/trig/hyperbolics.htm
20
 * These formulas seem to agree with excel's implementation.
21
 * 
22
 */
23
public class Acosh extends NumericFunction {
24
    
25
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
26
        new ValueEvalToNumericXlator((short)
27
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
28
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
29
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
30
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
31
                | ValueEvalToNumericXlator.STRING_IS_PARSED
32
                ));
33
34
    protected ValueEvalToNumericXlator getXlator() {
35
        return NUM_XLATOR;
36
    }
37
38
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
39
        double d = 0;
40
        ValueEval retval = null;
41
        
42
        switch (operands.length) {
43
        default:
44
            break;
45
        case 1:
46
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
47
            if (ve instanceof NumericValueEval) {
48
                NumericValueEval ne = (NumericValueEval) ve;
49
                d = ne.getNumberValue();
50
            }
51
        }
52
        
53
        if (retval == null) {
54
            d = Math.log(Math.sqrt(Math.pow(d, 2) - 1) + d);
55
            retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
56
        }
57
        return retval;
58
    }
59
60
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Activecell.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Activecell extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Addbar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Addbar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Addcommand.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Addcommand extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Addmenu.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Addmenu extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Address.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Address extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Addtoolbar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Addtoolbar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/And.java (+73 lines)
Added Link Here
1
/*
2
 * Created on May 9, 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
import org.apache.poi.hssf.record.formula.eval.StringEval;
12
import org.apache.poi.hssf.record.formula.eval.ValueEval;
13
14
/**
15
 * @author
16
 *  
17
 */
18
public class And extends BooleanFunction {
19
20
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
21
        ValueEval retval = null;
22
        boolean b = true;
23
        boolean atleastOneNonBlank = false;
24
        
25
        /*
26
         * Note: do not abort the loop if b is false, since we could be
27
         * dealing with errorevals later. 
28
         */
29
        outer:
30
        for (int i=0, iSize=operands.length; i<iSize; i++) {
31
            if (operands[i] instanceof AreaEval) {
32
                AreaEval ae = (AreaEval) operands[i];
33
                ValueEval[] values = ae.getValues();
34
                for (int j=0, jSize=values.length; j<jSize; j++) {
35
                    ValueEval tempVe = tempVe = singleOperandEvaluate(values[j], srcRow, srcCol, true);
36
                    if (tempVe instanceof BoolEval) {
37
                        b = b && ((BoolEval) tempVe).getBooleanValue();
38
                        atleastOneNonBlank = true;
39
                    }
40
                    else if (tempVe instanceof ErrorEval) {
41
                        retval = tempVe;
42
                        break outer;
43
                    }
44
                }
45
            }
46
            else {
47
                ValueEval tempVe = singleOperandEvaluate(operands[i], srcRow, srcCol, false);
48
                if (tempVe instanceof BoolEval) {
49
                    b = b && ((BoolEval) tempVe).getBooleanValue();
50
                    atleastOneNonBlank = true;
51
                }
52
                else if (tempVe instanceof StringEval) {
53
                    retval = ErrorEval.VALUE_INVALID;
54
                }
55
                else if (tempVe instanceof ErrorEval) {
56
                    retval = tempVe;
57
                    break outer;
58
                }
59
            }
60
        }
61
        
62
        if (!atleastOneNonBlank) {
63
            retval = ErrorEval.VALUE_INVALID;
64
        }
65
        
66
        if (retval == null) { // if no error
67
            retval = b ? BoolEval.TRUE : BoolEval.FALSE;
68
        }
69
        
70
        return retval;
71
    }
72
73
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Apptitle.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Apptitle extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Areas.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Areas extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Argument.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Argument extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asc.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Asc extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asin.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Asin extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            d = Math.asin(d);
57
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
58
        }
59
        return retval;
60
    }
61
62
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Asinh.java (+67 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 * Support for hyperbolic trig functions was added as a part of 
18
 * Java distribution only in JDK1.5. This class uses custom 
19
 * naive implementation based on formulas at:
20
 * http://www.math2.org/math/trig/hyperbolics.htm
21
 * These formulas seem to agree with excel's implementation.
22
 * 
23
 */
24
public class Asinh extends NumericFunction {
25
    
26
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
27
        new ValueEvalToNumericXlator((short)
28
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
29
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
30
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
31
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
32
                | ValueEvalToNumericXlator.STRING_IS_PARSED
33
                ));
34
35
    protected ValueEvalToNumericXlator getXlator() {
36
        return NUM_XLATOR;
37
    }
38
39
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
40
        double d = 0;
41
        ValueEval retval = null;
42
        
43
        switch (operands.length) {
44
        default:
45
            break;
46
        case 1:
47
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
48
            if (ve instanceof NumericValueEval) {
49
                NumericValueEval ne = (NumericValueEval) ve;
50
                d = ne.getNumberValue();
51
            }
52
            else if (ve instanceof BlankEval) {
53
                // do nothing
54
            }
55
            else {
56
                retval = ErrorEval.NUM_ERROR;
57
            }
58
        }
59
        
60
        if (retval == null) {
61
            d = Math.log(Math.sqrt(Math.pow(d, 2) + 1) + d);
62
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
63
        }
64
        return retval;
65
    }
66
67
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Atan extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            d = Math.atan(d);
57
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
58
        }
59
        return retval;
60
    }
61
62
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atan2.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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Atan2 extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d0 = 0;
36
        double d1 = 0;
37
        ValueEval retval = null;
38
        
39
        switch (operands.length) {
40
        default:
41
            break;
42
        case 2:
43
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
44
            if (ve instanceof NumericValueEval) {
45
                NumericValueEval ne = (NumericValueEval) ve;
46
                d0 = ne.getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.NUM_ERROR;
53
            }
54
            
55
            if (retval == null) {
56
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
57
                if (ve instanceof NumericValueEval) {
58
                    NumericValueEval ne = (NumericValueEval) ve;
59
                    d1 = ne.getNumberValue();
60
                }
61
                else if (ve instanceof BlankEval) {
62
                    // do nothing
63
                }
64
                else {
65
                    retval = ErrorEval.NUM_ERROR;
66
                }
67
            }
68
        }
69
        
70
        if (retval == null) {
71
            double d = (d0 == d1 && d1 == 0) ? Double.NaN : Math.atan2(d1, d0);
72
            retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
73
        }
74
        return retval;
75
    }
76
77
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Atanh.java (+67 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 * Support for hyperbolic trig functions was added as a part of 
18
 * Java distribution only in JDK1.5. This class uses custom 
19
 * naive implementation based on formulas at:
20
 * http://www.math2.org/math/trig/hyperbolics.htm
21
 * These formulas seem to agree with excel's implementation.
22
 * 
23
 */
24
public class Atanh extends NumericFunction {
25
    
26
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
27
        new ValueEvalToNumericXlator((short)
28
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
29
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
30
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
31
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
32
                | ValueEvalToNumericXlator.STRING_IS_PARSED
33
                ));
34
35
    protected ValueEvalToNumericXlator getXlator() {
36
        return NUM_XLATOR;
37
    }
38
39
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
40
        double d = 0;
41
        ValueEval retval = null;
42
        
43
        switch (operands.length) {
44
        default:
45
            break;
46
        case 1:
47
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
48
            if (ve instanceof NumericValueEval) {
49
                NumericValueEval ne = (NumericValueEval) ve;
50
                d = ne.getNumberValue();
51
            }
52
            else if (ve instanceof BlankEval) {
53
                // do nothing
54
            }
55
            else {
56
                retval = ErrorEval.NUM_ERROR;
57
            }
58
        }
59
        
60
        if (retval == null) {
61
            d = Math.log((1 + d)/(1 - d)) / 2;
62
            retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
63
        }
64
        return retval;
65
    }
66
67
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Avedev.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Avedev extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Average.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Average extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Averagea.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Averagea extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Betadist.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Betadist extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Betainv.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Betainv extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Binomdist.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Binomdist extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/BooleanFunction.java (+84 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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
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
/**
18
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
19
 * Here are the general rules concerning Boolean functions:
20
 * <ol>
21
 * <li> Blanks are not either true or false
22
 * <li> Strings are not either true or false (even strings "true" 
23
 * or "TRUE" or "0" etc.)
24
 * <li> Numbers: 0 is false. Any other number is TRUE.
25
 * <li> References are evaluated and above rules apply.
26
 * <li> Areas: Individual cells in area are evaluated and checked to 
27
 * see if they are blanks, strings etc.
28
 * </ol>
29
 */
30
public abstract class BooleanFunction implements Function {
31
32
    protected ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol, boolean stringsAreBlanks) {
33
        ValueEval retval;
34
        
35
        if (eval instanceof RefEval) {
36
            RefEval re = (RefEval) eval;
37
            ValueEval ve = re.getInnerValueEval();
38
            retval = internalResolve(ve, true);
39
        }
40
        else {
41
            retval = internalResolve(eval, stringsAreBlanks);
42
        }
43
        
44
        return retval;
45
    }
46
    
47
    private ValueEval internalResolve(Eval ve, boolean stringsAreBlanks) {
48
        ValueEval retval = null;
49
        
50
        // blankeval is returned as is
51
        if (ve instanceof BlankEval) {
52
            retval = BlankEval.INSTANCE;
53
        }
54
        
55
        // stringeval
56
        else if (ve instanceof StringEval) {
57
            retval = stringsAreBlanks ? (ValueEval) BlankEval.INSTANCE : (StringEval) ve;
58
        }
59
        
60
        // bools are bools :)
61
        else if (ve instanceof BoolEval) {
62
            retval = (BoolEval) ve;
63
        }
64
        
65
        // convert numbers to bool
66
        else if (ve instanceof NumericValueEval) {
67
            NumericValueEval ne = (NumericValueEval) ve;
68
            double d = ne.getNumberValue();
69
            retval = Double.isNaN(d) 
70
                    ? (ValueEval) ErrorEval.VALUE_INVALID
71
                    : (d != 0) 
72
                        ? BoolEval.TRUE
73
                        : BoolEval.FALSE;
74
        }
75
        
76
        // since refevals
77
        else {
78
            retval = ErrorEval.VALUE_INVALID;
79
        }
80
        
81
        return retval;
82
        
83
    }
84
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Call.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Call extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Caller.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Caller extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cancelkey.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Cancelkey extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ceiling.java (+14 lines)
Added Link Here
1
/*
2
 * Created on May 6, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
8
/**
9
 * @author 
10
 *  
11
 */
12
public class Ceiling extends DefaultFunctionImpl {
13
    
14
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cell.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Cell extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Char.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Char extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Checkcommand.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Checkcommand extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Chidist.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Chidist extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Chiinv.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Chiinv extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Chitest.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Chitest extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Choose.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Choose extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Clean.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Clean extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Code.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Code extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Column.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Column extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Columns.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Columns extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Combin.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Combin extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Concatenate.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Concatenate extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Confidence.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Confidence extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Correl.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Correl extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cos.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Cos extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            d = Math.cos(d);
57
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
58
        }
59
        return retval;
60
    }
61
62
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Cosh.java (+64 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Cosh extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            double ePowX = Math.pow(E, d);
57
            double ePowNegX = Math.pow(E, -d);
58
            d = (ePowX + ePowNegX) / 2;
59
            retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
60
        }
61
        return retval;
62
    }
63
64
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Count.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Count extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Counta.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Counta extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Countblank.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Countblank extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Countif.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Countif extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Covar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Covar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Createobject.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Createobject extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Critbinom.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Critbinom extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Customrepeat.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Customrepeat extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Customundo.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Customundo extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Date.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Date extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Datedif.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Datedif extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Datestring.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Datestring extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Datevalue.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Datevalue extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Daverage.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Daverage extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Day.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Day extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Days360.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Days360 extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Db.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Db extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dbcs.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dbcs extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dcount.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dcount extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dcounta.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dcounta extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Ddb.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Ddb extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/DefaultFunctionImpl.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.ErrorEval;
8
import org.apache.poi.hssf.record.formula.eval.Eval;
9
10
/**
11
 * 
12
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
13
 * This is the default implementation of a Function class. 
14
 * The default behaviour is to return a non-standard ErrorEval
15
 * "ErrorEval.FUNCTION_NOT_IMPLEMENTED". This error should alert 
16
 * the user that the formula contained a function that is not
17
 * yet implemented.
18
 */
19
public abstract class DefaultFunctionImpl implements Function {
20
21
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
22
        return ErrorEval.FUNCTION_NOT_IMPLEMENTED;
23
    }
24
25
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Degrees.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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Degrees extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            retval = ErrorEval.VALUE_INVALID;
41
            break;
42
        case 1:
43
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
44
            if (ve instanceof NumericValueEval) {
45
                NumericValueEval ne = (NumericValueEval) ve;
46
                d = ne.getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.NUM_ERROR;
53
            }
54
        }
55
        
56
        if (retval == null) {
57
            d = Math.toDegrees(d);
58
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
59
        }
60
        return retval;
61
    }
62
63
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Deletebar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Deletebar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Deletecommand.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Deletecommand extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Deletemenu.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Deletemenu extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Deletetoolbar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Deletetoolbar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Deref.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Deref extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Devsq.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Devsq extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dget.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dget extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dialogbox.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dialogbox extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Directory.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Directory extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dmax.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dmax extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dmin.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dmin extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Documents.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Documents extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dollar.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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Dollar extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            break;
41
        case 1:
42
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
43
            if (ve instanceof NumericValueEval) {
44
                NumericValueEval ne = (NumericValueEval) ve;
45
                d = ne.getNumberValue();
46
            }
47
            else if (ve instanceof BlankEval) {
48
                // do nothing
49
            }
50
            else {
51
                retval = ErrorEval.NUM_ERROR;
52
            }
53
        }
54
        
55
        if (retval == null) {
56
            retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
57
        }
58
        return retval;
59
    }
60
61
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dproduct.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dproduct extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dstdev.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dstdev extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dstdevp.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dstdevp extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dsum.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dsum extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dvar.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dvar extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Dvarp.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Dvarp extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Echo.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Echo extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Enablecommand.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Enablecommand extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Enabletool.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Enabletool extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Error.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Error extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Errortype.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Errortype extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Evaluate.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Evaluate extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Even.java (+71 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Even extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26
                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
27
                | ValueEvalToNumericXlator.STRING_IS_PARSED
28
                ));
29
30
    protected ValueEvalToNumericXlator getXlator() {
31
        return NUM_XLATOR;
32
    }
33
34
    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
35
        double d = 0;
36
        ValueEval retval = null;
37
        
38
        switch (operands.length) {
39
        default:
40
            retval = ErrorEval.VALUE_INVALID;
41
            break;
42
        case 1:
43
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
44
            if (ve instanceof NumericValueEval) {
45
                NumericValueEval ne = (NumericValueEval) ve;
46
                d = ne.getNumberValue();
47
            }
48
            else if (ve instanceof BlankEval) {
49
                // do nothing
50
            }
51
            else {
52
                retval = ErrorEval.NUM_ERROR;
53
            }
54
        }
55
        
56
        if (retval == null) {
57
            if (!Double.isNaN(d) && !Double.isInfinite(d)) {
58
                d = (d==0) 
59
                    ? 0 
60
                    : (((long) (d/2))*2 == d)
61
                        ? d
62
                        : (d < 0) 
63
                            ? ((((long) (d/2))<<1)-2) 
64
                            : ((((long) (d/2))<<1)+2);
65
            }
66
            retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
67
        }
68
        return retval;
69
    }
70
71
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exact.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Exact extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exec.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Exec extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Execute.java (+13 lines)
Added Link Here
1
/*
2
 * Created on May 15, 2005
3
 *
4
 */
5
package org.apache.poi.hssf.record.formula.functions;
6
7
/**
8
 * @author 
9
 *
10
 */
11
public class Execute extends DefaultFunctionImpl {
12
13
}
(-)src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Exp.java (+62 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.BlankEval;
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
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
14
15
/**
16
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
17
 *  
18
 */
19
public class Exp extends NumericFunction {
20
    
21
    private static final ValueEvalToNumericXlator NUM_XLATOR = 
22
        new ValueEvalToNumericXlator((short)
23
                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
24
                | ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
25
                | ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
26