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 28215641f..373b65382 100644 --- a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java @@ -15,9 +15,7 @@ import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.function.FunctionMetadata; import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; -import org.apache.poi.ss.formula.functions.EDate; -import org.apache.poi.ss.formula.functions.FreeRefFunction; -import org.apache.poi.ss.formula.functions.Sumifs; +import org.apache.poi.ss.formula.functions.*; import org.apache.poi.ss.formula.udf.UDFFinder; import java.util.*; @@ -74,7 +72,7 @@ public final class AnalysisToolPak implements UDFFinder { r(m, "BIN2DEC", null); r(m, "BIN2HEX", null); r(m, "BIN2OCT", null); - r(m, "COMPLEX", null); + r(m, "COMPLEX", Complex.instance); r(m, "CONVERT", null); r(m, "COUNTIFS", null); r(m, "COUPDAYBS", null); diff --git a/src/java/org/apache/poi/ss/formula/functions/Complex.java b/src/java/org/apache/poi/ss/formula/functions/Complex.java index d37ab70de..0c3981102 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Complex.java +++ b/src/java/org/apache/poi/ss/formula/functions/Complex.java @@ -1,5 +1,6 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.*; /** @@ -30,7 +31,9 @@ import org.apache.poi.ss.formula.eval.*; * * @author cedric dot walter @ gmail dot com */ -public class Complex extends Var2or3ArgFunction { +public class Complex extends Var2or3ArgFunction implements FreeRefFunction { + + public static final FreeRefFunction instance = new Complex(); public static final String DEFAULT_SUFFIX = "i"; public static final String SUPPORTED_SUFFIX = "j"; @@ -116,4 +119,15 @@ public class Complex extends Var2or3ArgFunction { return (number == Math.floor(number)) && !Double.isInfinite(number); } + @Override + public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { + if (args.length == 2) { + return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); + } + if (args.length == 3) { + return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1], args[2]); + } + + return ErrorEval.VALUE_INVALID; + } } diff --git a/test-data/spreadsheet/ComplexFunctionTestCaseData.xls b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls new file mode 100644 index 000000000..0d72e7d14 Binary files /dev/null and b/test-data/spreadsheet/ComplexFunctionTestCaseData.xls differ