diff --git a/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML.csproj
index 0b68acf..e761588 100644
--- a/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML.csproj
@@ -54,6 +54,7 @@
+
diff --git a/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs b/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs
index dcf4b76..a01a138 100644
--- a/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs
+++ b/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs
@@ -128,7 +128,7 @@
{
Boolean match = isText
? filter.Condition(row.Cell(kp.Key).GetString())
- : row.Cell(kp.Key).DataType == XLCellValues.Number &&
+ : row.Cell(kp.Key).DataType == XLDataType.Number &&
filter.Condition(row.Cell(kp.Key).GetDouble());
if (firstFilter)
{
diff --git a/ClosedXML/Excel/AutoFilters/XLFilterColumn.cs b/ClosedXML/Excel/AutoFilters/XLFilterColumn.cs
index a045910..a624708 100644
--- a/ClosedXML/Excel/AutoFilters/XLFilterColumn.cs
+++ b/ClosedXML/Excel/AutoFilters/XLFilterColumn.cs
@@ -206,7 +206,7 @@
}
var cell = row.Cell(_column);
- if (cell.DataType != XLCellValues.Number || !condition(cell.GetDouble())) continue;
+ if (cell.DataType != XLDataType.Number || !condition(cell.GetDouble())) continue;
row.WorksheetRow().Unhide();
foundOne = true;
}
@@ -224,7 +224,7 @@
{
using (var subColumn = column.Column(2, column.CellCount()))
{
- var cellsUsed = subColumn.CellsUsed(c => c.DataType == XLCellValues.Number);
+ var cellsUsed = subColumn.CellsUsed(c => c.DataType == XLDataType.Number);
if (takeTop)
{
if (type == XLTopBottomType.Items)
@@ -284,7 +284,7 @@
}
var cell = row.Cell(_column);
- if (cell.DataType != XLCellValues.Number || !condition(cell.GetDouble())) continue;
+ if (cell.DataType != XLDataType.Number || !condition(cell.GetDouble())) continue;
row.WorksheetRow().Unhide();
foundOne = true;
}
@@ -304,17 +304,17 @@
{
using (var subColumn = column.Column(2, column.CellCount()))
{
- Double average = subColumn.CellsUsed(c => c.DataType == XLCellValues.Number).Select(c => c.GetDouble()).Average();
+ Double average = subColumn.CellsUsed(c => c.DataType == XLDataType.Number).Select(c => c.GetDouble()).Average();
if (aboveAverage)
{
return
- subColumn.CellsUsed(c => c.DataType == XLCellValues.Number).
+ subColumn.CellsUsed(c => c.DataType == XLDataType.Number).
Select(c => c.GetDouble()).Where(c => c > average).Distinct();
}
return
- subColumn.CellsUsed(c => c.DataType == XLCellValues.Number).
+ subColumn.CellsUsed(c => c.DataType == XLDataType.Number).
Select(c => c.GetDouble()).Where(c => c < average).Distinct();
}
@@ -371,7 +371,7 @@
{
Boolean match = isText
? condition(row.Cell(_column).GetString())
- : row.Cell(_column).DataType == XLCellValues.Number &&
+ : row.Cell(_column).DataType == XLDataType.Number &&
condition(row.Cell(_column).GetDouble());
if (match)
row.WorksheetRow().Unhide();
@@ -390,4 +390,4 @@
public IXLFilterColumn SetDynamicValue(Double value) { DynamicValue = value; return this; }
}
-}
\ No newline at end of file
+}
diff --git a/ClosedXML/Excel/AutoFilters/XLFilteredColumn.cs b/ClosedXML/Excel/AutoFilters/XLFilteredColumn.cs
index f9d2bd3..1f11d83 100644
--- a/ClosedXML/Excel/AutoFilters/XLFilteredColumn.cs
+++ b/ClosedXML/Excel/AutoFilters/XLFilteredColumn.cs
@@ -46,7 +46,7 @@
if ((isText && condition(row.Cell(_column).GetString())) || (
!isText &&
row.Cell(_column).DataType ==
- XLCellValues.Number &&
+ XLDataType.Number &&
condition(
row.Cell(_column).GetValue()))
)
diff --git a/ClosedXML/Excel/CalcEngine/CalcEngineHelpers.cs b/ClosedXML/Excel/CalcEngine/CalcEngineHelpers.cs
index 83d872a..e1b6e51 100644
--- a/ClosedXML/Excel/CalcEngine/CalcEngineHelpers.cs
+++ b/ClosedXML/Excel/CalcEngine/CalcEngineHelpers.cs
@@ -44,6 +44,9 @@
var cs = criteria as string;
if (cs != null)
{
+ if (value is string && (value as string).Trim() == "")
+ return cs == "";
+
if (cs == "")
return cs.Equals(value);
@@ -54,7 +57,7 @@
var expression = string.Format("{0}{1}", value, cs);
// add quotes if necessary
- var pattern = @"(\w+)(\W+)(\w+)";
+ var pattern = @"([\w\s]+)(\W+)(\w+)";
var m = Regex.Match(expression, pattern);
if (m.Groups.Count == 4)
{
diff --git a/ClosedXML/Excel/CalcEngine/Expression.cs b/ClosedXML/Excel/CalcEngine/Expression.cs
index b9a29ca..ff1288c 100644
--- a/ClosedXML/Excel/CalcEngine/Expression.cs
+++ b/ClosedXML/Excel/CalcEngine/Expression.cs
@@ -113,6 +113,11 @@
return ((DateTime)v).ToOADate();
}
+ if (v is TimeSpan)
+ {
+ return ((TimeSpan)v).TotalDays;
+ }
+
// handle nulls
if (v == null || v is string)
{
diff --git a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
index 43fce93..dfd9d25 100644
--- a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
+++ b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs
@@ -17,17 +17,23 @@
ce.RegisterFunction("ABS", 1, Abs);
ce.RegisterFunction("ACOS", 1, Acos);
ce.RegisterFunction("ACOSH", 1, Acosh);
+ ce.RegisterFunction("ACOT", 1, Acot);
+ ce.RegisterFunction("ACOTH", 1, Acoth);
+ ce.RegisterFunction("ARABIC", 1, Arabic);
ce.RegisterFunction("ASIN", 1, Asin);
ce.RegisterFunction("ASINH", 1, Asinh);
ce.RegisterFunction("ATAN", 1, Atan);
ce.RegisterFunction("ATAN2", 2, Atan2);
ce.RegisterFunction("ATANH", 1, Atanh);
+ ce.RegisterFunction("BASE", 2, 3, Base);
ce.RegisterFunction("CEILING", 1, Ceiling);
ce.RegisterFunction("COMBIN", 2, Combin);
ce.RegisterFunction("COMBINA", 2, CombinA);
ce.RegisterFunction("COS", 1, Cos);
ce.RegisterFunction("COSH", 1, Cosh);
ce.RegisterFunction("COT", 1, Cot);
+ ce.RegisterFunction("COTH", 1, Coth);
+ ce.RegisterFunction("CSC", 1, Csc);
ce.RegisterFunction("CSCH", 1, Csch);
ce.RegisterFunction("DECIMAL", 2, MathTrig.Decimal);
ce.RegisterFunction("DEGREES", 1, Degrees);
@@ -61,6 +67,8 @@
ce.RegisterFunction("ROUND", 2, Round);
ce.RegisterFunction("ROUNDDOWN", 2, RoundDown);
ce.RegisterFunction("ROUNDUP", 1, 2, RoundUp);
+ ce.RegisterFunction("SEC", 1, Sec);
+ ce.RegisterFunction("SECH", 1, Sech);
ce.RegisterFunction("SERIESSUM", 4, SeriesSum);
ce.RegisterFunction("SIGN", 1, Sign);
ce.RegisterFunction("SIN", 1, Sin);
@@ -88,12 +96,20 @@
private static object Acos(List p)
{
+ double input = p[0];
+ if (Math.Abs(input) > 1)
+ throw new NumberException();
+
return Math.Acos(p[0]);
}
private static object Asin(List p)
{
- return Math.Asin(p[0]);
+ double input = p[0];
+ if (Math.Abs(input) > 1)
+ throw new NumberException();
+
+ return Math.Asin(input);
}
private static object Atan(List p)
@@ -103,7 +119,12 @@
private static object Atan2(List p)
{
- return Math.Atan2(p[0], p[1]);
+ double x = p[0];
+ double y = p[1];
+ if (x == 0 && y == 0)
+ throw new DivisionByZeroException();
+
+ return Math.Atan2(y, x);
}
private static object Ceiling(List p)
@@ -131,6 +152,24 @@
return 1 / tan;
}
+ private static object Coth(List p)
+ {
+ double input = p[0];
+ if (input == 0)
+ throw new DivisionByZeroException();
+
+ return 1 / Math.Tanh(input);
+ }
+
+ private static object Csc(List p)
+ {
+ double input = p[0];
+ if (input == 0)
+ throw new DivisionByZeroException();
+
+ return 1 / Math.Sin(input);
+ }
+
private static object Csch(List p)
{
if (Math.Abs((double)p[0].Evaluate()) < Double.Epsilon)
@@ -290,7 +329,9 @@
{
// get parameters
var range = p[0] as IEnumerable; // range of values to match the criteria against
- var sumRange = p.Count < 3 ? range : p[2] as IEnumerable; // range of values to sum up
+ var sumRange = p.Count < 3 ?
+ p[0] as XObjectExpression :
+ p[2] as XObjectExpression; // range of values to sum up
var criteria = p[1].Evaluate(); // the criteria to evaluate
// build list of values in range and sumRange
@@ -299,10 +340,10 @@
{
rangeValues.Add(value);
}
- var sumRangeValues = new List