das974 has uploaded a patch.
Description:
ClosedXml cannot handle formulas that refer to text values for date and numeric calculations.
Steps
1) Create new Workbook,
2) In A1, type '11/20/2013 6:00 - (make sure to include the apostrophe)
3) In B1, type '11/20/2013 9:00 - (make sure to include the apostrophe)
4) In C1, type the enter the formula =B1-A1
5) In A2 type '1
6) In B2 type '5
7) in C2 type B1-A1
8) Save and use the ClosedXml library to get the value of C1 and C2
Expected:
Value of C1 is .0125 - matches value in Excel and cached value
Value of C2 is 4 - matched value in Excel and cached value
Actual:
Value of C1 is 0
Value of C2 is 0
Excel is able to convert text to dates or numbers in formulas if appropriate and so should the ClosedXml library to keep the behaviors consistent. I believe that the Expression logic should be improved to handle these scenarios similar to how the Excel client application handles it - by attempting to parse the strings and give the best answer possible without modifying the underlying datatype.
In the ClosedXML.Excel.CalcEngine.Expression type, the operator override for double should be expanded as shown below, but I think that the parsing logic should be more elaborate to handle multiple cultures. The following change is sufficient to handle most US scenarios and is an improvement over what is already available.
//Handle values that formatted as strings and try to parse them.
if (v is string)
{
DateTime date;
if (DateTime.TryParse(v as string, out date))
return date.ToOADate();
double doubleVal;
if (Double.TryParse(v as string, out doubleVal))
return (doubleVal);
}