Lines 20-25
Link Here
|
20 |
*/ |
20 |
*/ |
21 |
package org.apache.poi.hssf.record.formula.functions; |
21 |
package org.apache.poi.hssf.record.formula.functions; |
22 |
|
22 |
|
23 |
public class Year extends NotImplementedFunction { |
23 |
import org.apache.poi.hssf.record.formula.eval.BlankEval; |
|
|
24 |
import org.apache.poi.hssf.record.formula.eval.ErrorEval; |
25 |
import org.apache.poi.hssf.record.formula.eval.Eval; |
26 |
import org.apache.poi.hssf.record.formula.eval.NumberEval; |
27 |
import org.apache.poi.hssf.record.formula.eval.NumericValueEval; |
28 |
import org.apache.poi.hssf.record.formula.eval.ValueEval; |
29 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
24 |
|
30 |
|
25 |
} |
31 |
/** |
|
|
32 |
* |
33 |
* @author Guenter Kickinger g.kickinger@gmx.net |
34 |
* |
35 |
*/ |
36 |
|
37 |
public class Year extends NumericFunction { |
38 |
|
39 |
/* (non-Javadoc) |
40 |
* @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short) |
41 |
*/ |
42 |
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { |
43 |
ValueEval retval = null; |
44 |
|
45 |
switch (operands.length) { |
46 |
default: |
47 |
retval = ErrorEval.VALUE_INVALID; |
48 |
break; |
49 |
case 1: |
50 |
ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol); |
51 |
if (ve instanceof NumericValueEval) { |
52 |
NumericValueEval ne = (NumericValueEval) ve; |
53 |
if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) { |
54 |
java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue()); |
55 |
retval = new NumberEval(d.getYear()+1900); |
56 |
} else { |
57 |
retval = ErrorEval.NUM_ERROR; |
58 |
} |
59 |
} |
60 |
else if (ve instanceof BlankEval) { |
61 |
// do nothing |
62 |
} else { |
63 |
retval = ErrorEval.NUM_ERROR; |
64 |
} |
65 |
} |
66 |
return retval; |
67 |
} |
68 |
} |