[bug-62275] in vlooup function, treat optional 4th param as true if the value is not provided
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1836857 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3c4d0086fa
commit
83b60f4777
@ -52,7 +52,12 @@ public final class Vlookup extends Var3or4ArgFunction {
|
|||||||
// lookup_value , table_array, range_lookup, find lookup value, col_index, fetch result
|
// lookup_value , table_array, range_lookup, find lookup value, col_index, fetch result
|
||||||
ValueEval lookupValue = OperandResolver.getSingleValue(lookup_value, srcRowIndex, srcColumnIndex);
|
ValueEval lookupValue = OperandResolver.getSingleValue(lookup_value, srcRowIndex, srcColumnIndex);
|
||||||
TwoDEval tableArray = LookupUtils.resolveTableArrayArg(table_array);
|
TwoDEval tableArray = LookupUtils.resolveTableArrayArg(table_array);
|
||||||
boolean isRangeLookup = LookupUtils.resolveRangeLookupArg(range_lookup, srcRowIndex, srcColumnIndex);
|
boolean isRangeLookup;
|
||||||
|
try {
|
||||||
|
isRangeLookup = LookupUtils.resolveRangeLookupArg(range_lookup, srcRowIndex, srcColumnIndex);
|
||||||
|
} catch(RuntimeException e) {
|
||||||
|
isRangeLookup = true;
|
||||||
|
}
|
||||||
int rowIndex = LookupUtils.lookupIndexOfValue(lookupValue, LookupUtils.createColumnVector(tableArray, 0), isRangeLookup);
|
int rowIndex = LookupUtils.lookupIndexOfValue(lookupValue, LookupUtils.createColumnVector(tableArray, 0), isRangeLookup);
|
||||||
int colIndex = LookupUtils.resolveRowOrColIndexArg(col_index, srcRowIndex, srcColumnIndex);
|
int colIndex = LookupUtils.resolveRowOrColIndexArg(col_index, srcRowIndex, srcColumnIndex);
|
||||||
ValueVector resultCol = createResultColumnVector(tableArray, colIndex);
|
ValueVector resultCol = createResultColumnVector(tableArray, colIndex);
|
||||||
|
@ -437,16 +437,17 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
|
|||||||
assertEquals("D 0,068", evaluator.evaluate(wb.getSheetAt(0).getRow(1).getCell(1)));
|
assertEquals("D 0,068", evaluator.evaluate(wb.getSheetAt(0).getRow(1).getCell(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBug62275() throws IOException {
|
public void testBug62275() throws IOException {
|
||||||
try (Workbook wb = new XSSFWorkbook()) {
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
Sheet sheet = wb.createSheet();
|
Sheet sheet = wb.createSheet();
|
||||||
Row row = sheet.createRow(0);
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
Cell cell = row.createCell(0);
|
Cell cell = row.createCell(0);
|
||||||
cell.setCellFormula("vlookup(A2,B1:B5,2,)");
|
cell.setCellFormula("vlookup(A2,B1:B5,2,true)");
|
||||||
|
|
||||||
CreationHelper crateHelper = wb.getCreationHelper();
|
CreationHelper createHelper = wb.getCreationHelper();
|
||||||
FormulaEvaluator eval = crateHelper.createFormulaEvaluator();
|
FormulaEvaluator eval = createHelper.createFormulaEvaluator();
|
||||||
eval.evaluate(cell);
|
eval.evaluate(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user