Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions main/SS/Formula/Eval/FunctionEval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ private static Function[] ProduceFunctions()
retval[37] = new Or(); // OR
retval[38] = new Not(); // NOT
retval[39] = NumericFunction.MOD; // MOD
retval[40] = new NotImplementedFunction("DCOUNT"); // DCOUNT
retval[41] = new NotImplementedFunction("DSUM"); // DSUM
retval[42] = new NotImplementedFunction("DAVERAGE"); // DAVERAGE
retval[40] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DCOUNT); // DCOUNT
retval[41] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DSUM); // DSUM
retval[42] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DAVERAGE); // DAVERAGE
retval[43] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DMIN); // DMIN
retval[44] = new NotImplementedFunction("DMAX"); // DMAX
retval[45] = new NotImplementedFunction("DSTDEV"); // DSTDEV
retval[44] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DMAX);// DMAX
retval[45] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DSTDEV); // DSTDEV
retval[46] = AggregateFunction.VAR; // VAR
retval[47] = new NotImplementedFunction("DVAR"); // DVAR
retval[47] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DVAR);
retval[48] = TextFunction.TEXT; // TEXT
retval[49] = new NotImplementedFunction("LINEST"); // LINEST
retval[50] = new NotImplementedFunction("TREND"); // TREND
Expand Down Expand Up @@ -281,17 +281,17 @@ private static Function[] ProduceFunctions()
retval[186] = new NotImplementedFunction("GetWORKSPACE"); // GetWORKSPACE
retval[187] = new NotImplementedFunction("GetWINDOW"); // GetWINDOW
retval[188] = new NotImplementedFunction("GetDOCUMENT"); // GetDOCUMENT
retval[189] = new NotImplementedFunction("DPRODUCT"); // DPRODUCT
retval[189] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DPRODUCT);
retval[190] = LogicalFunction.ISNONTEXT; // IsNONTEXT
retval[191] = new NotImplementedFunction("GetNOTE"); // GetNOTE
retval[192] = new NotImplementedFunction("NOTE"); // NOTE
retval[193] = new NotImplementedFunction("STDEVP"); // STDEVP
retval[193] = AggregateFunction.STDEVP;
retval[194] = AggregateFunction.VARP; // VARP
retval[195] = new NotImplementedFunction("DSTDEVP"); // DSTDEVP
retval[196] = new NotImplementedFunction("DVARP"); // DVARP
retval[195] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DSTDEVP);
retval[196] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DVARP);
retval[197] = NumericFunction.TRUNC; // TRUNC
retval[198] = LogicalFunction.ISLOGICAL; // IsLOGICAL
retval[199] = new NotImplementedFunction("DCOUNTA"); // DCOUNTA
retval[199] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DCOUNTA);
retval[200] = new NotImplementedFunction("DELETEBAR"); // DELETEBAR
retval[201] = new NotImplementedFunction("UNREGISTER"); // UNREGISTER
retval[204] = NumericFunction.DOLLAR; // USDOLLAR
Expand Down
63 changes: 63 additions & 0 deletions main/SS/Formula/Functions/DAverage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

namespace NPOI.SS.Formula.Functions
{
using ExtendedNumerics;
using NPOI.SS.Formula.Eval;
using System.Numerics;

/// <summary>
/// Implementation of the DAverage function:
/// Gets the average value of a column in an area with given conditions.
/// </summary>
public sealed class DAverage : IDStarAlgorithm
{
private long count;
private double total;
public bool ProcessMatch(ValueEval eval)
{
if(eval is NumericValueEval)
{
count++;
total += ((NumericValueEval) eval).NumberValue;
}
return true;
}
public ValueEval Result
{
get
{
return count == 0 ? NumberEval.ZERO : new NumberEval(GetAverage());
}
}

private double GetAverage()
{
return Divide(total, count);
}

private static double Divide(double total, long count)
{
return (double) BigDecimal.Divide(new BigDecimal(total), new BigInteger(count));
}

public bool AllowEmptyMatchField { get; } = false;
}
}


54 changes: 54 additions & 0 deletions main/SS/Formula/Functions/DCount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace NPOI.SS.Formula.Functions
{
using NPOI.SS.Formula.Eval;

/// <summary>
/// Implementation of the DCount function:
/// Counts the number of numeric cells in a column in an area with given conditions.
/// </summary>
public sealed class DCount : IDStarAlgorithm
{
private long count;
public bool ProcessMatch(ValueEval eval)
{
if(eval is NumericValueEval)
{
count++;
}
return true;
}
public ValueEval Result
{
get
{
return new NumberEval(count);
}
}
public bool AllowEmptyMatchField { get; } = true;
}
}

55 changes: 55 additions & 0 deletions main/SS/Formula/Functions/DCountA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace NPOI.SS.Formula.Functions
{
using NPOI.SS.Formula.Eval;

/// <summary>
/// Implementation of the DCountA function:
/// Counts the number of non-blank cells in a column in an area with given conditions.
/// </summary>
public sealed class DCountA : IDStarAlgorithm
{
private long count;
public bool ProcessMatch(ValueEval eval)
{
if(!(eval is BlankEval))
{
count++;
}
return true;
}

public ValueEval Result
{
get
{
return new NumberEval(count);
}
}
public bool AllowEmptyMatchField { get; } = true;
}
}

28 changes: 21 additions & 7 deletions main/SS/Formula/Functions/DGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ public class DGet : IDStarAlgorithm

public bool ProcessMatch(ValueEval eval)
{
if (result == null) // First match, just Set the value.
if(result == null) // First match, just Set the value.
{
result = eval;
}
else // There was a previous match, since there is only exactly one allowed, bail out1.
{
result = ErrorEval.NUM_ERROR;
return false;
if(result is BlankEval)
{
result = eval;
}
else
{
// We have a previous filled result.
if(!(eval is BlankEval))
{
result = ErrorEval.NUM_ERROR;
return false;
}
}
}

return true;
Expand All @@ -50,17 +61,18 @@ public ValueEval Result
{
get
{
if (result == null)
if(result == null)
{
return ErrorEval.VALUE_INVALID;
}
if (result is BlankEval) {
if(result is BlankEval)
{
return ErrorEval.VALUE_INVALID;
}
else
try
{
if (OperandResolver.CoerceValueToString(OperandResolver.GetSingleValue(result, 0, 0)).Equals(""))
if(OperandResolver.CoerceValueToString(OperandResolver.GetSingleValue(result, 0, 0)).Equals(""))
{
return ErrorEval.VALUE_INVALID;
}
Expand All @@ -69,12 +81,14 @@ public ValueEval Result
return result;
}
}
catch (EvaluationException e)
catch(EvaluationException e)
{
return e.GetErrorEval();
}
}
}

public bool AllowEmptyMatchField { get; } = false;
}
}

85 changes: 85 additions & 0 deletions main/SS/Formula/Functions/DMax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace NPOI.SS.Formula.Functions
{
using NPOI.SS.Formula.Eval;




/// <summary>
/// <para>
/// Implementation of the DMax function:
/// Finds the maximum value of a column in an area with given conditions.
/// </para>
/// <para>
/// TODO:
/// - functions as conditions
/// </para>
/// </summary>
public sealed class DMax : IDStarAlgorithm
{
private ValueEval maximumValue;
public bool ProcessMatch(ValueEval eval)
{
if(eval is NumericValueEval)
{
if(maximumValue == null)
{ // First match, just Set the value.
maximumValue = eval;
}
else
{ // There was a previous match, find the new minimum.
double currentValue = ((NumericValueEval)eval).NumberValue;
double oldValue = ((NumericValueEval)maximumValue).NumberValue;
if(currentValue > oldValue)
{
maximumValue = eval;
}
}
}

return true;
}
public ValueEval Result
{
get
{
if(maximumValue == null)
{
return NumberEval.ZERO;
}
else
{
return maximumValue;
}
}

}
public bool AllowEmptyMatchField { get; } = false;
}
}


2 changes: 2 additions & 0 deletions main/SS/Formula/Functions/DMin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public ValueEval Result
}
}
}

public bool AllowEmptyMatchField { get; } = false;
}

}
Loading