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/RefAndLookup/Index.cs @ 12074

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

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 2.2 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.RefAndLookup
10{
11    public class Index : ExcelFunction
12    {
13        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
14        {
15            ValidateArguments(arguments, 2);
16            var arg1 = arguments.ElementAt(0);
17            var args = arg1.Value as IEnumerable<FunctionArgument>;
18            var crf = new CompileResultFactory();
19            if (args != null)
20            {
21                var index = ArgToInt(arguments, 1);
22                if (index > args.Count())
23                {
24                    throw new ExcelErrorValueException(eErrorType.Ref);
25                }
26                var candidate = args.ElementAt(index - 1);
27                //Commented JK-Can be any data type
28                //if (!IsNumber(candidate.Value))
29                //{
30                //    throw new ExcelErrorValueException(eErrorType.Value);
31                //}
32                //return CreateResult(ConvertUtil.GetValueDouble(candidate.Value), DataType.Decimal);
33                return crf.Create(candidate.Value);
34            }
35            if (arg1.IsExcelRange)
36            {
37                var row = ArgToInt(arguments, 1);                 
38                var col = arguments.Count()>2 ? ArgToInt(arguments, 2) : 1;
39                var ri=arg1.ValueAsRangeInfo;
40                if (row > ri.Address._toRow - ri.Address._fromRow + 1 ||
41                    col > ri.Address._toCol - ri.Address._fromCol + 1)
42                {
43                    ThrowExcelErrorValueException(eErrorType.Ref);
44                }
45                var candidate = ri.GetOffset(row-1, col-1);
46                //Commented JK-Can be any data type
47                //if (!IsNumber(candidate.Value))   
48                //{
49                //    throw new ExcelErrorValueException(eErrorType.Value);
50                //}
51                return crf.Create(candidate);
52            }
53            throw new NotImplementedException();
54        }
55    }
56}
Note: See TracBrowser for help on using the repository browser.