Esempio n. 1
0
        private CompileResult CompileSingleCell(ExcelDataProvider.IRangeInfo result)
        {
            if (result.Address.Address == ExcelErrorValue.Values.Ref)
            {
                return(new CompileResult(eErrorType.Ref));
            }
            var cell = result.FirstOrDefault();

            if (cell == null)
            {
                return(CompileResult.Empty);
            }
            var factory       = new CompileResultFactory();
            var compileResult = factory.Create(cell.Value);

            if (_negate)
            {
                if (compileResult.IsNumeric)
                {
                    compileResult = new CompileResult(compileResult.ResultNumeric * -1, compileResult.DataType);
                }
                else if (compileResult.DataType == DataType.String)
                {
                    if (compileResult.ResultValue is string resultString && double.TryParse(resultString, out double resultDouble))
                    {
                        compileResult = new CompileResult((resultDouble * -1).ToString(), compileResult.DataType);
                    }
                    else
                    {
                        compileResult = new CompileResult(eErrorType.Value);
                    }
                }
            }
Esempio n. 2
0
File: If.cs Progetto: acinep/epplus
 public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
 {
     ValidateArguments(arguments, 3);
     var condition = ArgToBool(arguments, 0);
     var firstStatement = arguments.ElementAt(1).Value;
     var secondStatement = arguments.ElementAt(2).Value;
     var factory = new CompileResultFactory();
     return condition ? factory.Create(firstStatement) : factory.Create(secondStatement);
 }
Esempio n. 3
0
        private CompileResult CompileSingleCell(ExcelDataProvider.IRangeInfo result)
        {
            var cell          = result.First();
            var factory       = new CompileResultFactory();
            var compileResult = factory.Create(cell.Value);

            if (_negate && compileResult.IsNumeric)
            {
                compileResult = new CompileResult(compileResult.ResultNumeric * -1, compileResult.DataType);
            }
            compileResult.IsHiddenCell = cell.IsHiddenRow;
            return(compileResult);
        }
Esempio n. 4
0
        public override CompileResult Compile()
        {
            var c    = this._parsingContext.Scopes.Current;
            var name = _parsingContext.ExcelDataProvider.GetName(c.Address.Worksheet, ExpressionString);

            //var result = _parsingContext.Parser.Parse(value.ToString());

            if (name == null)
            {
                throw (new Exceptions.ExcelErrorValueException(ExcelErrorValue.Create(eErrorType.Name)));
            }
            if (name.Value == null)
            {
                return(null);
            }
            if (name.Value is ExcelDataProvider.IRangeInfo)
            {
                var range = (ExcelDataProvider.IRangeInfo)name.Value;
                if (range.IsMulti && (range.Count() > 1 || (range.Address.Columns > 1 || range.Address.Rows > 1)))
                {
                    return(new CompileResult(name.Value, DataType.Enumerable));
                }
                else
                {
                    if (range.IsEmpty)
                    {
                        return(null);
                    }
                    var factory = new CompileResultFactory();
                    return(factory.Create(range.First().Value));
                }
            }
            else
            {
                var factory = new CompileResultFactory();
                return(factory.Create(name.Value));
            }



            //return new CompileResultFactory().Create(result);
        }
Esempio n. 5
0
 public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
 {
     ValidateArguments(arguments, 2);
     var arg1 = arguments.ElementAt(0);
     var args = arg1.Value as IEnumerable<FunctionArgument>;
     var crf = new CompileResultFactory();
     if (args != null)
     {
         var index = ArgToInt(arguments, 1);
         if (index > args.Count())
         {
             throw new ExcelErrorValueException(eErrorType.Ref);
         }
         var candidate = args.ElementAt(index - 1);
         //Commented JK-Can be any data type
         //if (!IsNumber(candidate.Value))
         //{
         //    throw new ExcelErrorValueException(eErrorType.Value);
         //}
         //return CreateResult(ConvertUtil.GetValueDouble(candidate.Value), DataType.Decimal);
         return crf.Create(candidate.Value);
     }
     if (arg1.IsExcelRange)
     {
         var row = ArgToInt(arguments, 1);                 
         var col = arguments.Count()>2 ? ArgToInt(arguments, 2) : 1;
         var ri=arg1.ValueAsRangeInfo;
         if (row > ri.Address._toRow - ri.Address._fromRow + 1 ||
             col > ri.Address._toCol - ri.Address._fromCol + 1)
         {
             ThrowExcelErrorValueException(eErrorType.Ref);
         }
         var candidate = ri.GetOffset(row-1, col-1);
         //Commented JK-Can be any data type
         //if (!IsNumber(candidate.Value))   
         //{
         //    throw new ExcelErrorValueException(eErrorType.Value);
         //}
         return crf.Create(candidate);
     }
     throw new NotImplementedException();
 }
Esempio n. 6
0
        public override CompileResult Compile()
        {
            var c = this._parsingContext.Scopes.Current;
            var name = _parsingContext.ExcelDataProvider.GetName(c.Address.Worksheet, ExpressionString);
            //var result = _parsingContext.Parser.Parse(value.ToString());

            if (name == null)
            {
                throw (new Exceptions.ExcelErrorValueException(ExcelErrorValue.Create(eErrorType.Name)));
            }
            if (name.Value==null)
            {
                return null;
            }
            if (name.Value is ExcelDataProvider.IRangeInfo)
            {
                var range = (ExcelDataProvider.IRangeInfo)name.Value;
                if (range.IsMulti)
                {
                    return new CompileResult(name.Value, DataType.Enumerable);
                }
                else
                {
                    if (range.IsEmpty)
                    {
                        return null;
                    }
                    var factory = new CompileResultFactory();
                    return factory.Create(range.First().Value);
                }
            }
            else
            {                
                var factory = new CompileResultFactory();
                return factory.Create(name.Value);
            }

            
            
            //return new CompileResultFactory().Create(result);
        }
Esempio n. 7
0
 public LookupFunction(ValueMatcher valueMatcher, CompileResultFactory compileResultFactory)
 {
     _valueMatcher = valueMatcher;
     _compileResultFactory = compileResultFactory;
 }
 public ExpressionEvaluator(WildCardValueMatcher wildCardValueMatcher, CompileResultFactory compileResultFactory)
 {
     _wildCardValueMatcher = wildCardValueMatcher;
     _compileResultFactory = compileResultFactory;
 }
 public NumericExpressionEvaluator(ValueMatcher valueMatcher, CompileResultFactory compileResultFactory)
 {
     _valueMatcher = valueMatcher;
     _compileResultFactory = compileResultFactory;
 }
Esempio n. 10
0
 private CompileResult CompileSingleCell(ExcelDataProvider.IRangeInfo result)
 {
     var cell = result.First();
     var factory = new CompileResultFactory();
     var compileResult = factory.Create(cell.Value);
     if (_negate && compileResult.IsNumeric)
     {
         compileResult = new CompileResult(compileResult.ResultNumeric * -1, compileResult.DataType);
     }
     compileResult.IsHiddenCell = cell.IsHiddenRow;
     return compileResult;
 }