// too few arguments
return ErrorEval.VALUE_INVALID;
}
Eval firstArg = args[0];
if(firstArg instanceof AreaEval) {
AreaEval reference = (AreaEval) firstArg;
int rowIx = 0;
int columnIx = 0;
int areaIx = 0;
switch(nArgs) {
case 4:
areaIx = convertIndexArgToZeroBase(args[3]);
throw new RuntimeException("Incomplete code" +
" - don't know how to support the 'area_num' parameter yet)");
// Excel expression might look like this "INDEX( (A1:B4, C3:D6, D2:E5 ), 1, 2, 3)
// In this example, the 3rd area would be used i.e. D2:E5, and the overall result would be E2
// Token array might be encoded like this: MemAreaPtg, AreaPtg, AreaPtg, UnionPtg, UnionPtg, ParenthesesPtg
// The formula parser doesn't seem to support this yet. Not sure if the evaluator does either
case 3:
columnIx = convertIndexArgToZeroBase(args[2]);
case 2:
rowIx = convertIndexArgToZeroBase(args[1]);
break;
default:
// too many arguments
return ErrorEval.VALUE_INVALID;
}
int nColumns = reference.getLastColumn()-reference.getFirstColumn()+1;
int index = rowIx * nColumns + columnIx;
return reference.getValues()[index];
}
// else the other variation of this function takes an array as the first argument
// it seems like interface 'ArrayEval' does not even exist yet