aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2020-10-25 07:21:45 +0000
committerDominik Stadler <centic@apache.org>2020-10-25 07:21:45 +0000
commit352f5a034c12d09756deac2a32ccf9770c39a664 (patch)
treebab65f7350dbfb9fac081871620062b9e217b0f4
parent19944379e14947b1d29abf056630d22d1fafa9fc (diff)
downloadpoi-352f5a034c12d09756deac2a32ccf9770c39a664.tar.gz
poi-352f5a034c12d09756deac2a32ccf9770c39a664.zip
Fix bug 64238: Make LOOKUP functions deal with empty last arg correctly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882827 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/LookupUtils.java24
-rw-r--r--test-data/spreadsheet/LookupFunctionsTestCaseData.xlsbin68096 -> 70144 bytes
2 files changed, 15 insertions, 9 deletions
diff --git a/src/java/org/apache/poi/ss/formula/functions/LookupUtils.java b/src/java/org/apache/poi/ss/formula/functions/LookupUtils.java
index cccb6d64ad..9af09c301b 100644
--- a/src/java/org/apache/poi/ss/formula/functions/LookupUtils.java
+++ b/src/java/org/apache/poi/ss/formula/functions/LookupUtils.java
@@ -25,6 +25,7 @@ import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.formula.eval.MissingArgEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
@@ -133,7 +134,7 @@ final class LookupUtils {
return new ColumnVector(tableArray, relativeColumnIndex);
}
/**
- * @return <code>null</code> if the supplied area is neither a single row nor a single colum
+ * @return <code>null</code> if the supplied area is neither a single row nor a single column
*/
public static ValueVector createVector(TwoDEval ae) {
if (ae.isColumn()) {
@@ -144,7 +145,7 @@ final class LookupUtils {
}
return null;
}
-
+
public static ValueVector createVector(RefEval re) {
return new SheetVector(re);
}
@@ -276,11 +277,11 @@ final class LookupUtils {
private static final class StringLookupComparer extends LookupValueComparerBase {
-
- private String _value;
+
+ private final String _value;
private final Pattern _wildCardPattern;
- private boolean _matchExact;
- private boolean _isMatchFunction;
+ private final boolean _matchExact;
+ private final boolean _isMatchFunction;
protected StringLookupComparer(StringEval se, boolean matchExact, boolean isMatchFunction) {
super(se);
@@ -311,7 +312,7 @@ final class LookupUtils {
}
}
private static final class NumberLookupComparer extends LookupValueComparerBase {
- private double _value;
+ private final double _value;
protected NumberLookupComparer(NumberEval ne) {
super(ne);
@@ -326,7 +327,7 @@ final class LookupUtils {
}
}
private static final class BooleanLookupComparer extends LookupValueComparerBase {
- private boolean _value;
+ private final boolean _value;
protected BooleanLookupComparer(BoolEval be) {
super(be);
@@ -434,6 +435,11 @@ final class LookupUtils {
public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval valEval = OperandResolver.getSingleValue(rangeLookupArg, srcCellRow, srcCellCol);
+ if(valEval == MissingArgEval.instance) {
+ // Tricky:
+ // forth arg exists but is not supplied: "=VLOOKUP(A1,A2:A4,2,)"
+ return false;
+ }
if(valEval instanceof BlankEval) {
// Tricky:
// fourth arg supplied but evaluates to blank
@@ -457,7 +463,7 @@ final class LookupUtils {
Boolean b = Countif.parseBoolean(stringValue);
if(b != null) {
// string converted to boolean OK
- return b.booleanValue();
+ return b;
}
// Even more trickiness:
// Note - even if the StringEval represents a number value (for example "1"),
diff --git a/test-data/spreadsheet/LookupFunctionsTestCaseData.xls b/test-data/spreadsheet/LookupFunctionsTestCaseData.xls
index 56b6f12a00..d9e9b517d8 100644
--- a/test-data/spreadsheet/LookupFunctionsTestCaseData.xls
+++ b/test-data/spreadsheet/LookupFunctionsTestCaseData.xls
Binary files differ