Lines 27-32
Link Here
|
27 |
import org.apache.poi.ss.formula.eval.ValueEval; |
27 |
import org.apache.poi.ss.formula.eval.ValueEval; |
28 |
import org.apache.poi.ss.usermodel.DateUtil; |
28 |
import org.apache.poi.ss.usermodel.DateUtil; |
29 |
import org.apache.poi.util.LocaleUtil; |
29 |
import org.apache.poi.util.LocaleUtil; |
|
|
30 |
import org.apache.poi.util.POILogger; |
31 |
import org.apache.poi.util.POILogFactory; |
30 |
|
32 |
|
31 |
/** |
33 |
/** |
32 |
* Implementation for Excel WeekNum() function.<p/> |
34 |
* Implementation for Excel WeekNum() function.<p/> |
Lines 43-51
Link Here
|
43 |
* 1 Week begins on Sunday. Weekdays are numbered 1 through 7. |
45 |
* 1 Week begins on Sunday. Weekdays are numbered 1 through 7. |
44 |
* 2 Week begins on Monday. Weekdays are numbered 1 through 7. |
46 |
* 2 Week begins on Monday. Weekdays are numbered 1 through 7. |
45 |
*/ |
47 |
*/ |
46 |
public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction { |
48 |
public class WeekNum extends Var1or2ArgFunction implements FreeRefFunction { |
|
|
49 |
private static final POILogger LOGGER = POILogFactory.getLogger(WeekNum.class); |
47 |
public static final FreeRefFunction instance = new WeekNum(); |
50 |
public static final FreeRefFunction instance = new WeekNum(); |
|
|
51 |
private static final ValueEval DEFAULT_RETURN_TYPE = new NumberEval(1); |
48 |
|
52 |
|
|
|
53 |
@Override |
54 |
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE) { |
55 |
return evaluate(srcRowIndex, srcColumnIndex, serialNumVE, DEFAULT_RETURN_TYPE); |
56 |
} |
57 |
|
58 |
@Override |
49 |
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) { |
59 |
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) { |
50 |
double serialNum = 0.0; |
60 |
double serialNum = 0.0; |
51 |
try { |
61 |
try { |
Lines 80-89
Link Here
|
80 |
return cal.get(Calendar.WEEK_OF_YEAR); |
90 |
return cal.get(Calendar.WEEK_OF_YEAR); |
81 |
} |
91 |
} |
82 |
|
92 |
|
|
|
93 |
@Override |
83 |
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { |
94 |
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { |
|
|
95 |
if (args.length == 1) { |
96 |
return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], DEFAULT_RETURN_TYPE); |
97 |
} |
84 |
if (args.length == 2) { |
98 |
if (args.length == 2) { |
85 |
return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); |
99 |
return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); |
86 |
} |
100 |
} |
|
|
101 |
if (LOGGER.check(POILogger.WARN)) { |
102 |
LOGGER.log(POILogger.WARN, "WeekNum() expected 1-2 args, got " + args.length); |
103 |
} |
87 |
return ErrorEval.VALUE_INVALID; |
104 |
return ErrorEval.VALUE_INVALID; |
88 |
} |
105 |
} |
89 |
} |
106 |
} |