diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
index 5f7d00c..193e78a 100644
--- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
@@ -147,6 +147,8 @@
+
+
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
index 84fb2f0..e30ecb1 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
@@ -62,12 +62,12 @@
ce.RegisterFunction("SIN", 1, Sin);
ce.RegisterFunction("SINH", 1, Sinh);
ce.RegisterFunction("SQRT", 1, Sqrt);
- //ce.RegisterFunction("SQRTPI", SqrtPi, 1);
- //ce.RegisterFunction("SUBTOTAL", Subtotal, 1);
+ ce.RegisterFunction("SQRTPI", 1, SqrtPi);
+ ce.RegisterFunction("SUBTOTAL", 2, 255, Subtotal);
ce.RegisterFunction("SUM", 1, int.MaxValue, Sum);
ce.RegisterFunction("SUMIF", 2, 3, SumIf);
- //ce.RegisterFunction("SUMPRODUCT", SumProduct, 1);
- //ce.RegisterFunction("SUMSQ", SumSq, 1);
+ //ce.RegisterFunction("SUMPRODUCT", 1, SumProduct);
+ ce.RegisterFunction("SUMSQ", 1, 255, SumSq);
//ce.RegisterFunction("SUMX2MY2", SumX2MY2, 1);
//ce.RegisterFunction("SUMX2PY2", SumX2PY2, 1);
//ce.RegisterFunction("SUMXMY2", SumXMY2, 1);
@@ -589,5 +589,51 @@
return total;
}
+
+ private static object SqrtPi(List p)
+ {
+ var num = (Double)p[0];
+ return Math.Sqrt(Math.PI * num);
+ }
+
+ private static object Subtotal(List p)
+ {
+ var fId = (int)(Double)p[0];
+ var tally = new Tally(p.Skip(1));
+
+ switch (fId)
+ {
+ case 1:
+ return tally.Average();
+ case 2:
+ return tally.Count();
+ case 3:
+ return tally.CountA();
+ case 4:
+ return tally.Max();
+ case 5:
+ return tally.Min();
+ case 6:
+ return tally.Product();
+ case 7:
+ return tally.Std();
+ case 8:
+ return tally.StdP();
+ case 9:
+ return tally.Sum();
+ case 10:
+ return tally.Var();
+ case 11:
+ return tally.VarP();
+ default:
+ throw new ArgumentException("Function not supported.");
+ }
+ }
+
+ private static object SumSq(List p)
+ {
+ var t = new Tally(p);
+ return t.Numerics().Sum(v => Math.Pow(v, 2));
+ }
}
}
\ No newline at end of file
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Statistical.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Statistical.cs
index c0e91cd..973bb90 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Statistical.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Statistical.cs
@@ -209,12 +209,7 @@
// utility for tallying statistics
static Tally GetTally(List p, bool numbersOnly)
{
- var tally = new Tally(numbersOnly);
- foreach (Expression e in p)
- {
- tally.Add(e);
- }
- return tally;
+ return new Tally(p);
}
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Average.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Average.cs
new file mode 100644
index 0000000..5d002fc
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Average.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel.CalcEngine.Functions.Subtotals
+{
+ class Average
+ {
+ public static Object GetSubtotal(List list)
+ {
+ var tally = new Tally();
+ foreach (var e in list)
+ {
+ tally.Add(e);
+ }
+ return tally.Average();
+ }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Subtotal.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Subtotal.cs
new file mode 100644
index 0000000..2b7e6ee
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Subtotals/Subtotal.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel.CalcEngine.Functions.Subtotals
+{
+ abstract class Subtotal
+ {
+ protected readonly List exprList;
+
+ protected Subtotal(List list)
+ {
+ exprList = list;
+ }
+ public abstract Object Evaluate();
+
+ public static Object GetSubtotal(Int32 fId, List list)
+ {
+
+ switch (fId)
+ {
+ case 1:
+ return Average.GetSubtotal(list);
+ default:
+ throw new ArgumentException("Function not supported.");
+ }
+ }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Tally.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Tally.cs
index 989497a..c21be91 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Tally.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/CalcEngine/Functions/Tally.cs
@@ -1,4 +1,6 @@
using System;
+using System.Linq;
+using System.Collections.Generic;
using System.Net;
using System.Collections;
@@ -6,15 +8,15 @@
{
internal class Tally
{
- double _sum, _sum2, _cnt, _min, _max;
- bool _numbersOnly;
+ private readonly List