예제 #1
0
파일: Subtotal.cs 프로젝트: nxoxn/EPPlus
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            if (this.ArgumentsAreValid(arguments, 2, out eErrorType argumentError) == false)
            {
                return(new CompileResult(argumentError));
            }
            var funcNum = ArgToInt(arguments, 0);

            if (context.Scopes.Current.Parent != null && context.Scopes.Current.Parent.IsSubtotal)
            {
                return(CreateResult(0d, DataType.Decimal));
            }
            ExcelFunction function = null;

            if (!_functions.ContainsKey(funcNum))
            {
                return(new CompileResult(eErrorType.Value));
            }
            else
            {
                function = _functions[funcNum];
            }
            var actualArgs = arguments.Skip(1);

            if (actualArgs.All(a => a.Value == null))
            {
                return(new CompileResult(0, DataType.Integer));
            }
            var compileResult = function.Execute(actualArgs, context);

            compileResult.IsResultOfSubtotal = true;
            return(compileResult);
        }
예제 #2
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);
            var funcNum = ArgToInt(arguments, 0);

            if (context.Scopes.Current.Parent != null && context.Scopes.Current.Parent.IsSubtotal)
            {
                return(CreateResult(0d, DataType.Decimal));
            }
            var           actualArgs = arguments.Skip(1);
            ExcelFunction function   = null;

            function = GetFunctionByCalcType(funcNum);
            return(function.Execute(actualArgs, context));
        }