Exemplo n.º 1
0
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length < 3 || args.Length % 2 == 0)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            try
            {
                AreaEval sumRange = ConvertRangeArg(args[0]);

                // collect pairs of ranges and criteria
                AreaEval[]        ae = new AreaEval[(args.Length - 1) / 2];
                IMatchPredicate[] mp = new IMatchPredicate[ae.Length];
                for (int i = 1, k = 0; i < args.Length; i += 2, k++)
                {
                    ae[k] = ConvertRangeArg(args[i]);
                    mp[k] = Countif.CreateCriteriaPredicate(args[i + 1], ec.RowIndex, ec.ColumnIndex);
                }

                ValidateCriteriaRanges(ae, sumRange);

                double result = SumMatchingCells(ae, mp, sumRange);
                return(new NumberEval(result));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
Exemplo n.º 2
0
        private static ValueEval Eval(int srcRowIndex, int srcColumnIndex, ValueEval arg1, AreaEval aeRange,
                                      AreaEval aeSum)
        {
            // TODO - junit to prove last arg must be srcColumnIndex and not srcRowIndex
            IMatchPredicate mp     = Countif.CreateCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex);
            double          result = SumMatchingCells(aeRange, mp, aeSum);

            return(new NumberEval(result));
        }