Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/Excel/Functions/Math/Small.cs

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

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 879 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using OfficeOpenXml.FormulaParsing.ExpressionGraph;
6
7namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Math
8{
9    public class Small : ExcelFunction
10    {
11        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
12        {
13            ValidateArguments(arguments, 2);
14            var args = arguments.ElementAt(0);
15            var index = ArgToInt(arguments, 1) - 1;
16            var values = ArgsToDoubleEnumerable(new List<FunctionArgument> { args }, context);
17            ThrowExcelErrorValueExceptionIf(() => index < 0 || index >= values.Count(), eErrorType.Num);
18            var result = values.OrderBy(x => x).ElementAt(index);
19            return CreateResult(result, DataType.Decimal);
20        }
21    }
22}
Note: See TracBrowser for help on using the repository browser.