Exemple #1
0
        protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs)
        {
            object lastValue       = null;
            object lastLookupValue = null;
            int?   lastMatchResult = null;

            if (lookupArgs.SearchedValue == null)
            {
                throw new ExcelErrorValueException("Lookupfunction failed to lookup value", ExcelErrorValue.Create(eErrorType.NA));
            }
            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, lookupArgs.SearchedValue);
                if (matchResult != 0)
                {
                    if (lastValue != null && navigator.CurrentValue == null)
                    {
                        break;
                    }

                    if (lookupArgs.RangeLookup)
                    {
                        if (lastValue == null && matchResult > 0)
                        {
                            ThrowExcelErrorValueException(eErrorType.NA);
                        }
                        if (lastValue != null && matchResult > 0 && lastMatchResult < 0)
                        {
                            return(_compileResultFactory.Create(lastLookupValue));
                        }
                        lastMatchResult = matchResult;
                        lastValue       = navigator.CurrentValue;
                        lastLookupValue = navigator.GetLookupValue();
                    }
                }
                else
                {
                    return(_compileResultFactory.Create(navigator.GetLookupValue()));
                }
            }while (navigator.MoveNext());

            if (lookupArgs.RangeLookup)
            {
                return(_compileResultFactory.Create(lastLookupValue));
            }

            throw new ExcelErrorValueException("Lookupfunction failed to lookup value", ExcelErrorValue.Create(eErrorType.NA));
        }
Exemple #2
0
        protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs)
        {
            object lastValue = null;
            object lastLookupValue = null;
            int? lastMatchResult = null;
            if (lookupArgs.SearchedValue == null)
            {
                return new CompileResult(ExcelErrorValue.Create(eErrorType.NA), DataType.ExcelError);
            }
            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, lookupArgs.SearchedValue);
                if (matchResult != 0)
                {
                    if (lastValue != null && navigator.CurrentValue == null) break;
                    
                    if (lookupArgs.RangeLookup)
                    {
                        if (lastValue == null && matchResult > 0)
                        {
                            ThrowExcelErrorValueException(eErrorType.NA);
                        }
                        if (lastValue != null && matchResult > 0 && lastMatchResult < 0)
                        {
                            return _compileResultFactory.Create(lastLookupValue);
                        }
                        lastMatchResult = matchResult;
                        lastValue = navigator.CurrentValue;
                        lastLookupValue = navigator.GetLookupValue();
                    }
                }
                else
                {
                    return _compileResultFactory.Create(navigator.GetLookupValue());
                }
            }
            while (navigator.MoveNext());

            if (lookupArgs.RangeLookup)
            {
                return _compileResultFactory.Create(lastLookupValue);
            }
            return new CompileResult(ExcelErrorValue.Create(eErrorType.NA), DataType.ExcelError);
        }
Exemple #3
0
        protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs)
        {
            object lastValue       = null;
            object lastLookupValue = null;
            int?   lastMatchResult = null;

            if (lookupArgs.SearchedValue == null)
            {
                return(new CompileResult(eErrorType.NA));
            }
            do
            {
                var matchResult = IsMatch(navigator.CurrentValue, lookupArgs.SearchedValue);
                if (matchResult != 0)
                {
                    if (lastValue != null && navigator.CurrentValue == null)
                    {
                        break;
                    }

                    if (!lookupArgs.RangeLookup)
                    {
                        continue;
                    }
                    if (lastValue == null && matchResult > 0)
                    {
                        return(new CompileResult(eErrorType.NA));
                    }
                    if (lastValue != null && matchResult > 0 && lastMatchResult < 0)
                    {
                        return(_compileResultFactory.Create(lastLookupValue));
                    }
                    lastMatchResult = matchResult;
                    lastValue       = navigator.CurrentValue;
                    lastLookupValue = navigator.GetLookupValue();
                }
                else
                {
                    return(_compileResultFactory.Create(navigator.GetLookupValue()));
                }
            }while (navigator.MoveNext());

            return(lookupArgs.RangeLookup ? _compileResultFactory.Create(lastLookupValue) : new CompileResult(eErrorType.NA));
        }