1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using OfficeOpenXml.FormulaParsing.Exceptions;
|
---|
6 | using OfficeOpenXml.FormulaParsing.ExpressionGraph;
|
---|
7 | using OfficeOpenXml.Utils;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|