Bug 63700: Make D* functions work with numeric result column

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2019-12-31 10:41:43 +00:00
parent 3cc54a8dff
commit 821e164041
2 changed files with 24 additions and 17 deletions

View File

@ -57,7 +57,7 @@ public final class DStarRunner implements Function3Arg {
private final Supplier<IDStarAlgorithm> implSupplier;
private DStarAlgorithmEnum(Supplier<IDStarAlgorithm> implSupplier) {
DStarAlgorithmEnum(Supplier<IDStarAlgorithm> implSupplier) {
this.implSupplier = implSupplier;
}
@ -158,8 +158,17 @@ public final class DStarRunner implements Function3Arg {
*/
private static int getColumnForName(ValueEval nameValueEval, AreaEval db)
throws EvaluationException {
String name = OperandResolver.coerceValueToString(nameValueEval);
return getColumnForString(db, name);
if (nameValueEval instanceof NumericValueEval) {
int columnNo = OperandResolver.coerceValueToInt(nameValueEval) - 1;
if (columnNo < 0 || columnNo >= db.getWidth()) {
return -1;
}
return columnNo;
}
else {
String name = OperandResolver.coerceValueToString(nameValueEval);
return getColumnForString(db, name);
}
}
/**
@ -169,10 +178,8 @@ public final class DStarRunner implements Function3Arg {
* @param db Database.
* @param name Column heading.
* @return Corresponding column number.
* @throws EvaluationException If it's not possible to turn all headings into strings.
*/
private static int getColumnForString(AreaEval db,String name)
throws EvaluationException {
private static int getColumnForString(AreaEval db,String name) {
int resultColumn = -1;
final int width = db.getWidth();
for(int column = 0; column < width; ++column) {

Binary file not shown.