Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/Excel/Functions/Information/N.cs @ 12074

Last change on this file since 12074 was 12074, checked in by sraggl, 9 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using OfficeOpenXml.FormulaParsing.Exceptions;
6using OfficeOpenXml.FormulaParsing.ExpressionGraph;
7using OfficeOpenXml.Utils;
8
9namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Information
10{
11    public class N : ExcelFunction
12    {
13        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
14        {
15            ValidateArguments(arguments, 1);
16            var arg = GetFirstValue(arguments);
17           
18            if (arg is bool)
19            {
20                var val = (bool) arg ? 1d : 0d;
21                return CreateResult(val, DataType.Decimal);
22            }
23            else if (IsNumeric(arg))
24            {
25                var val = ConvertUtil.GetValueDouble(arg);
26                return CreateResult(val, DataType.Decimal);
27            }
28            else if (arg is string)
29            {
30                return CreateResult(0d, DataType.Decimal);
31            }
32            else if (arg is ExcelErrorValue)
33            {
34                return CreateResult(arg, DataType.ExcelError);
35            }
36            throw new ExcelErrorValueException(eErrorType.Value);
37        }
38    }
39}
Note: See TracBrowser for help on using the repository browser.