diff --git a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java index 551ff75474..b866c61bf3 100644 --- a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java @@ -91,7 +91,7 @@ public final class AnalysisToolPak implements UDFFinder { r(m, "DEC2BIN", null); r(m, "DEC2HEX", null); r(m, "DEC2OCT", null); - r(m, "DELTA", null); + r(m, "DELTA", Delta.instance); r(m, "DISC", null); r(m, "DOLLARDE", null); r(m, "DOLLARFR", null); diff --git a/src/java/org/apache/poi/ss/formula/functions/Delta.java b/src/java/org/apache/poi/ss/formula/functions/Delta.java index 8488189aa5..2f1bd88dfc 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Delta.java +++ b/src/java/org/apache/poi/ss/formula/functions/Delta.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.*; import java.math.BigDecimal; @@ -37,7 +38,9 @@ import java.math.BigDecimal; * * @author cedric dot walter @ gmail dot com */ -public final class Delta extends Fixed2ArgFunction { +public final class Delta extends Fixed2ArgFunction implements FreeRefFunction { + + public static final FreeRefFunction instance = new Delta(); private final static NumberEval ONE = new NumberEval(1); private final static NumberEval ZERO = new NumberEval(0); @@ -72,4 +75,11 @@ public final class Delta extends Fixed2ArgFunction { return result == 0 ? ONE : ZERO; } + public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { + if (args.length == 2) { + return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); + } + + return ErrorEval.VALUE_INVALID; + } } \ No newline at end of file diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java new file mode 100644 index 0000000000..47bea2134a --- /dev/null +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java @@ -0,0 +1,13 @@ +package org.apache.poi.ss.formula.functions; + +/** +* Tests DELTA() as loaded from a test data spreadsheet.
+* +* @author cedric dot walter @ gmail dot com +*/ +public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet { + + protected String getFilename() { + return "DeltaFunctionTestCaseData.xls"; + } +} diff --git a/test-data/spreadsheet/DeltaFunctionTestCaseData.xls b/test-data/spreadsheet/DeltaFunctionTestCaseData.xls new file mode 100644 index 0000000000..e66e96cc69 Binary files /dev/null and b/test-data/spreadsheet/DeltaFunctionTestCaseData.xls differ