mirror of https://github.com/apache/poi.git
initial work on example 5
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7e240d41f1
commit
6ca520e32d
|
@ -49,15 +49,15 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction {
|
|||
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
|
||||
int srcRowIndex = ec.getRowIndex();
|
||||
int srcColumnIndex = ec.getColumnIndex();
|
||||
return _evaluate(args, srcRowIndex, srcColumnIndex, ec.isSingleValue());
|
||||
return _evaluate(args, srcRowIndex, srcColumnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
|
||||
return _evaluate(args, srcRowIndex, srcColumnIndex, false);
|
||||
return _evaluate(args, srcRowIndex, srcColumnIndex);
|
||||
}
|
||||
|
||||
private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex, boolean isSingleValue) {
|
||||
private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
|
||||
if (args.length < 3) {
|
||||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
|
@ -96,12 +96,12 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction {
|
|||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], notFound, matchMode, searchMode, isSingleValue);
|
||||
return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], notFound, matchMode, searchMode);
|
||||
}
|
||||
|
||||
private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookupEval, ValueEval indexEval,
|
||||
ValueEval returnEval, ValueEval notFound, LookupUtils.MatchMode matchMode,
|
||||
LookupUtils.SearchMode searchMode, boolean isSingleValue) {
|
||||
LookupUtils.SearchMode searchMode) {
|
||||
try {
|
||||
ValueEval lookupValue = OperandResolver.getSingleValue(lookupEval, srcRowIndex, srcColumnIndex);
|
||||
TwoDEval tableArray = LookupUtils.resolveTableArrayArg(indexEval);
|
||||
|
@ -120,7 +120,7 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction {
|
|||
if (returnEval instanceof AreaEval) {
|
||||
AreaEval area = (AreaEval)returnEval;
|
||||
int width = area.getWidth();
|
||||
if (isSingleValue || width <= 1) {
|
||||
if (width <= 1) {
|
||||
return notFound;
|
||||
}
|
||||
return notFoundAreaEval(notFound, width);
|
||||
|
@ -135,13 +135,6 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction {
|
|||
}
|
||||
if (returnEval instanceof AreaEval) {
|
||||
AreaEval area = (AreaEval)returnEval;
|
||||
if (isSingleValue) {
|
||||
if (tableArray.isColumn()) {
|
||||
return area.getRelativeValue(matchedIdx, 0);
|
||||
} else {
|
||||
return area.getRelativeValue(0, matchedIdx);
|
||||
}
|
||||
}
|
||||
if (tableArray.isColumn()) {
|
||||
return area.offset(matchedIdx, matchedIdx,0, area.getWidth() - 1);
|
||||
} else {
|
||||
|
|
|
@ -75,7 +75,7 @@ public class TestXLookupFunction {
|
|||
assertError(fe, cell, "XLOOKUP(B2,B5:B14,C5:D14)", FormulaError.NA);
|
||||
|
||||
String formulaText = "XLOOKUP(B2,B5:B14,C5:D14,\"not found\")";
|
||||
assertString(fe, cell, formulaText, "not found");
|
||||
assertString(fe, cell, "XLOOKUP(B2,B5:B14,C5:C14,\"not found\")", "not found");
|
||||
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFRow row1 = sheet.getRow(1);
|
||||
|
@ -105,9 +105,7 @@ public class TestXLookupFunction {
|
|||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
HSSFCell cell = wb.getSheetAt(0).getRow(2).createCell(3);
|
||||
assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,$C6:$C17)", 25000);
|
||||
assertDouble(fe, cell, "XLOOKUP($C3,$C5:$G5,$C6:$G17)", 50000);
|
||||
//TODO next test fails
|
||||
//assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,XLOOKUP($C3,$C5:$G5,$C6:$G17))", 25000);
|
||||
assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,XLOOKUP($C3,$C5:$G5,$C6:$G17))", 25000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue