Преглед изворни кода

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
tags/before_ooxml_3rd_edition
Dominik Stadler пре 3 година
родитељ
комит
352f5a034c

+ 15
- 9
src/java/org/apache/poi/ss/formula/functions/LookupUtils.java Прегледај датотеку

import org.apache.poi.ss.formula.eval.BoolEval; import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException; 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.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval; import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.OperandResolver;
return new ColumnVector(tableArray, relativeColumnIndex); 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) { public static ValueVector createVector(TwoDEval ae) {
if (ae.isColumn()) { if (ae.isColumn()) {
} }
return null; return null;
} }
public static ValueVector createVector(RefEval re) { public static ValueVector createVector(RefEval re) {
return new SheetVector(re); return new SheetVector(re);
} }




private static final class StringLookupComparer extends LookupValueComparerBase { private static final class StringLookupComparer extends LookupValueComparerBase {
private String _value;
private final String _value;
private final Pattern _wildCardPattern; 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) { protected StringLookupComparer(StringEval se, boolean matchExact, boolean isMatchFunction) {
super(se); super(se);
} }
} }
private static final class NumberLookupComparer extends LookupValueComparerBase { private static final class NumberLookupComparer extends LookupValueComparerBase {
private double _value;
private final double _value;


protected NumberLookupComparer(NumberEval ne) { protected NumberLookupComparer(NumberEval ne) {
super(ne); super(ne);
} }
} }
private static final class BooleanLookupComparer extends LookupValueComparerBase { private static final class BooleanLookupComparer extends LookupValueComparerBase {
private boolean _value;
private final boolean _value;


protected BooleanLookupComparer(BoolEval be) { protected BooleanLookupComparer(BoolEval be) {
super(be); super(be);
public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol) throws EvaluationException { public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol) throws EvaluationException {


ValueEval valEval = OperandResolver.getSingleValue(rangeLookupArg, srcCellRow, srcCellCol); 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) { if(valEval instanceof BlankEval) {
// Tricky: // Tricky:
// fourth arg supplied but evaluates to blank // fourth arg supplied but evaluates to blank
Boolean b = Countif.parseBoolean(stringValue); Boolean b = Countif.parseBoolean(stringValue);
if(b != null) { if(b != null) {
// string converted to boolean OK // string converted to boolean OK
return b.booleanValue();
return b;
} }
// Even more trickiness: // Even more trickiness:
// Note - even if the StringEval represents a number value (for example "1"), // Note - even if the StringEval represents a number value (for example "1"),

BIN
test-data/spreadsheet/LookupFunctionsTestCaseData.xls Прегледај датотеку


Loading…
Откажи
Сачувај