示例#1
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);
            var row = ArgToInt(arguments, 0) - 1;
            var col = ArgToInt(arguments, 1) - 1;

            ThrowExcelFunctionExceptionIf(() => row < 0 && col < 0, ExcelErrorCodes.Value);
            var referenceType = ExcelReferenceType.AbsoluteRowAndColumn;
            var worksheetSpec = string.Empty;

            if (arguments.Count() > 2)
            {
                var arg3 = ArgToInt(arguments, 2);
                ThrowExcelFunctionExceptionIf(() => arg3 < 1 || arg3 > 4, ExcelErrorCodes.Value);
                referenceType = (ExcelReferenceType)ArgToInt(arguments, 2);
            }
            if (arguments.Count() > 3)
            {
                var fourthArg = arguments.ElementAt(3).Value;
                if (fourthArg.GetType().Equals(typeof(bool)) && !(bool)fourthArg)
                {
                    throw new InvalidOperationException("Excelformulaparser does not support the R1C1 format!");
                }
                if (fourthArg.GetType().Equals(typeof(string)))
                {
                    worksheetSpec = fourthArg.ToString() + "!";
                }
            }
            var translator = new IndexToAddressTranslator(context.ExcelDataProvider, referenceType);

            return(CreateResult(worksheetSpec + translator.ToAddress(col, row), DataType.ExcelAddress));
        }
示例#2
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            if (this.ArgumentsAreValid(arguments, 2, out eErrorType argumentError) == false)
            {
                return(new CompileResult(argumentError));
            }
            var row = ArgToInt(arguments, 0);
            var col = ArgToInt(arguments, 1);

            if (row < 0 && col < 0)
            {
                return(new CompileResult(eErrorType.Value));
            }
            var referenceType = ExcelReferenceType.AbsoluteRowAndColumn;
            var worksheetSpec = string.Empty;

            if (arguments.Count() > 2)
            {
                var arg3 = ArgToInt(arguments, 2);
                if (arg3 < 1 || arg3 > 4)
                {
                    return(new CompileResult(eErrorType.Value));
                }
                referenceType = (ExcelReferenceType)ArgToInt(arguments, 2);
            }
            if (arguments.Count() > 3)
            {
                var fourthArg = arguments.ElementAt(3).Value;
                if (fourthArg is bool && !(bool)fourthArg)
                {
                    throw new InvalidOperationException("Excelformulaparser does not support the R1C1 format!");
                }
            }
            if (arguments.Count() > 4)
            {
                var fifthArg = arguments.ElementAt(4).Value;
                if (fifthArg is string && !string.IsNullOrEmpty(fifthArg.ToString()))
                {
                    worksheetSpec = fifthArg + "!";
                }
            }
            var translator = new IndexToAddressTranslator(context.ExcelDataProvider, referenceType);

            return(CreateResult(worksheetSpec + translator.ToAddress(col, row), DataType.ExcelAddress));
        }
示例#3
0
 private void SetupTranslator(int maxRows, ExcelReferenceType refType)
 {
     _excelDataProvider = A.Fake <ExcelDataProvider>();
     A.CallTo(() => _excelDataProvider.ExcelMaxRows).Returns(maxRows);
     _indexToAddressTranslator = new IndexToAddressTranslator(_excelDataProvider, refType);
 }
 private void SetupTranslator(int maxRows, ExcelReferenceType refType)
 {
     _excelDataProvider = MockRepository.GenerateStub <ExcelDataProvider>();
     _excelDataProvider.Stub(x => x.ExcelMaxRows).Return(maxRows);
     _indexToAddressTranslator = new IndexToAddressTranslator(_excelDataProvider, refType);
 }