Example #1
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 3);
            var dbAddress     = arguments.ElementAt(0).ValueAsRangeInfo.Address.Address;
            var field         = ArgToString(arguments, 1).ToLower(CultureInfo.InvariantCulture);
            var criteriaRange = arguments.ElementAt(2).ValueAsRangeInfo.Address.Address;

            var db       = new ExcelDatabase(context.ExcelDataProvider, dbAddress);
            var criteria = new ExcelDatabaseCriteria(context.ExcelDataProvider, criteriaRange);

            var    nHits  = 0;
            object retVal = null;

            while (db.HasMoreRows)
            {
                var dataRow = db.Read();
                if (!RowMatcher.IsMatch(dataRow, criteria))
                {
                    continue;
                }
                if (++nHits > 1)
                {
                    return(CreateResult(ExcelErrorValue.Values.Num, DataType.ExcelError));
                }
                retVal = dataRow[field];
            }
            return(new CompileResultFactory().Create(retVal));
        }
Example #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    dbAddress     = arguments.ElementAt(0).ValueAsRangeInfo.Address.Address;
            string field         = null;
            string criteriaRange = null;

            if (arguments.Count() == 2)
            {
                criteriaRange = arguments.ElementAt(1).ValueAsRangeInfo.Address.Address;
            }
            else
            {
                field         = ArgToString(arguments, 1).ToLower(CultureInfo.InvariantCulture);
                criteriaRange = arguments.ElementAt(2).ValueAsRangeInfo.Address.Address;
            }
            var db       = new ExcelDatabase(context.ExcelDataProvider, dbAddress);
            var criteria = new ExcelDatabaseCriteria(context.ExcelDataProvider, criteriaRange);

            var nHits = 0;

            while (db.HasMoreRows)
            {
                var dataRow = db.Read();
                if (RowMatcher.IsMatch(dataRow, criteria))
                {
                    // if a fieldname is supplied, count only this row if the value
                    // of the supplied field is not blank.
                    if (!string.IsNullOrEmpty(field))
                    {
                        var candidate = dataRow[field];
                        if (ShouldCount(candidate))
                        {
                            nHits++;
                        }
                    }
                    else
                    {
                        // no fieldname was supplied, always count matching row.
                        nHits++;
                    }
                }
            }
            return(CreateResult(nHits, DataType.Integer));
        }
Example #3
0
        public void IsMatchShouldMatchStrings1()
        {
            var data = new ExcelDatabaseRow();
            data["Crit1"] = "1";
            data["Crit2"] = 2;
            data["Crit3"] = 3;

            var crit = new Dictionary<ExcelDatabaseCriteriaField, object>();
            crit[new ExcelDatabaseCriteriaField("Crit1")] = "1";
            crit[new ExcelDatabaseCriteriaField("Crit3")] = 3;

            var matcher = new RowMatcher();

            var criteria = GetCriteria(crit);

            Assert.IsTrue(matcher.IsMatch(data, criteria));
        }
Example #4
0
        public void IsMatchShouldReturnFalseIfCriteriasDoesNotMatch()
        {
            var data = new ExcelDatabaseRow();
            data["Crit1"] = 1;
            data["Crit2"] = 2;
            data["Crit3"] = 3;

            var crit = new Dictionary<ExcelDatabaseCriteriaField, object>();
            crit[new ExcelDatabaseCriteriaField("Crit1")] = 1;
            crit[new ExcelDatabaseCriteriaField("Crit3")] = 4;

            var matcher = new RowMatcher();

            var criteria = GetCriteria(crit);

            Assert.IsFalse(matcher.IsMatch(data, criteria));
        }
Example #5
0
 public DatabaseFunction(RowMatcher rowMatcher)
 {
     RowMatcher = rowMatcher;
 }
Example #6
0
 public Dmax(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #7
0
        public DcountA(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #8
0
        public Dmax(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #9
0
 public DatabaseFunction(RowMatcher rowMatcher)
 {
     RowMatcher = rowMatcher;
 }
Example #10
0
        public Dsum(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #11
0
File: Dmin.cs Project: nxoxn/EPPlus
 public Dmin(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #12
0
         public Daverage(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #13
0
        public Dget(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #14
0
         public Dvar(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #15
0
 public DcountA(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #16
0
File: DSum.cs Project: nxoxn/EPPlus
 public Dsum(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #17
0
        public Dmin(RowMatcher rowMatcher)
            : base(rowMatcher)
        {

        }
Example #18
0
 public Dvar(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #19
0
 public Dcount(RowMatcher rowMatcher)
 {
     _rowMatcher = rowMatcher;
 }
Example #20
0
 public Dget(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #21
0
 public Daverage(RowMatcher rowMatcher)
     : base(rowMatcher)
 {
 }
Example #22
0
 public Dcount(RowMatcher rowMatcher)
 {
     _rowMatcher = rowMatcher;
 }