Exemplo n.º 1
0
 public void SumIfNumericExpression()
 {
     _worksheet.Cells["A1"].Value = null;
     _worksheet.Cells["A2"].Value = 1d;
     _worksheet.Cells["A3"].Value = "Not Empty";
     var func = new SumIf();
     IRangeInfo range = _provider.GetRange(_worksheet.Name, 1, 1, 3, 1);
     var args = FunctionsHelper.CreateArgs(range, 1d);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(1d, result.Result);
 }
Exemplo n.º 2
0
 public void SumIfNonNumeric()
 {
     _worksheet.Cells["A1"].Value = "Monday";
     _worksheet.Cells["A2"].Value = "Tuesday";
     _worksheet.Cells["A3"].Value = "Thursday";
     _worksheet.Cells["B1"].Value = 1d;
     _worksheet.Cells["B2"].Value = 3d;
     _worksheet.Cells["B3"].Value = 5d;
     var func = new SumIf();
     IRangeInfo range1 = _provider.GetRange(_worksheet.Name, 1, 1, 3, 1);
     IRangeInfo range2 = _provider.GetRange(_worksheet.Name, 1, 2, 3, 2);
     var args = FunctionsHelper.CreateArgs(range1, "T*day", range2);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(8d, result.Result);
 }
Exemplo n.º 3
0
 public BuiltInFunctions()
 {
     // Text
     Functions["len"] = new Len();
     Functions["lower"] = new Lower();
     Functions["upper"] = new Upper();
     Functions["left"] = new Left();
     Functions["right"] = new Right();
     Functions["mid"] = new Mid();
     Functions["replace"] = new Replace();
     Functions["rept"] = new Rept();
     Functions["substitute"] = new Substitute();
     Functions["concatenate"] = new Concatenate();
     Functions["char"] = new CharFunction();
     Functions["exact"] = new Exact();
     Functions["find"] = new Find();
     Functions["fixed"] = new Fixed();
     Functions["proper"] = new Proper();
     Functions["text"] = new Text.Text();
     Functions["t"] = new T();
     Functions["hyperlink"] = new Hyperlink();
     // Numbers
     Functions["int"] = new CInt();
     // Math
     Functions["abs"] = new Abs();
     Functions["asin"] = new Asin();
     Functions["asinh"] = new Asinh();
     Functions["cos"] = new Cos();
     Functions["cosh"] = new Cosh();
     Functions["power"] = new Power();
     Functions["sign"] = new Sign();
     Functions["sqrt"] = new Sqrt();
     Functions["sqrtpi"] = new SqrtPi();
     Functions["pi"] = new Pi();
     Functions["product"] = new Product();
     Functions["ceiling"] = new Ceiling();
     Functions["count"] = new Count();
     Functions["counta"] = new CountA();
     Functions["countblank"] = new CountBlank();
     Functions["countif"] = new CountIf();
     Functions["countifs"] = new CountIfs();
     Functions["fact"] = new Fact();
     Functions["floor"] = new Floor();
     Functions["sin"] = new Sin();
     Functions["sinh"] = new Sinh();
     Functions["sum"] = new Sum();
     Functions["sumif"] = new SumIf();
     Functions["sumifs"] = new SumIfs();
     Functions["sumproduct"] = new SumProduct();
     Functions["sumsq"] = new Sumsq();
     Functions["stdev"] = new Stdev();
     Functions["stdevp"] = new StdevP();
     Functions["stdev.s"] = new Stdev();
     Functions["stdev.p"] = new StdevP();
     Functions["subtotal"] = new Subtotal();
     Functions["exp"] = new Exp();
     Functions["log"] = new Log();
     Functions["log10"] = new Log10();
     Functions["ln"] = new Ln();
     Functions["max"] = new Max();
     Functions["maxa"] = new Maxa();
     Functions["median"] = new Median();
     Functions["min"] = new Min();
     Functions["mina"] = new Mina();
     Functions["mod"] = new Mod();
     Functions["average"] = new Average();
     Functions["averagea"] = new AverageA();
     Functions["averageif"] = new AverageIf();
     Functions["averageifs"] = new AverageIfs();
     Functions["round"] = new Round();
     Functions["rounddown"] = new Rounddown();
     Functions["roundup"] = new Roundup();
     Functions["rand"] = new Rand();
     Functions["randbetween"] = new RandBetween();
     Functions["quotient"] = new Quotient();
     Functions["trunc"] = new Trunc();
     Functions["tan"] = new Tan();
     Functions["tanh"] = new Tanh();
     Functions["atan"] = new Atan();
     Functions["atan2"] = new Atan2();
     Functions["atanh"] = new Atanh();
     Functions["acos"] = new Acos();
     Functions["acosh"] = new Acosh();
     Functions["var"] = new Var();
     Functions["varp"] = new VarP();
     Functions["large"] = new Large();
     Functions["small"] = new Small();
     Functions["degrees"] = new Degrees();
     // Information
     Functions["isblank"] = new IsBlank();
     Functions["isnumber"] = new IsNumber();
     Functions["istext"] = new IsText();
     Functions["isnontext"] = new IsNonText();
     Functions["iserror"] = new IsError();
     Functions["iserr"] = new IsErr();
     Functions["error.type"] = new ErrorType();
     Functions["iseven"] = new IsEven();
     Functions["isodd"] = new IsOdd();
     Functions["islogical"] = new IsLogical();
     Functions["isna"] = new IsNa();
     Functions["na"] = new Na();
     Functions["n"] = new N();
     // Logical
     Functions["if"] = new If();
     Functions["iferror"] = new IfError();
     Functions["ifna"] = new IfNa();
     Functions["not"] = new Not();
     Functions["and"] = new And();
     Functions["or"] = new Or();
     Functions["true"] = new True();
     Functions["false"] = new False();
     // Reference and lookup
     Functions["address"] = new Address();
     Functions["hlookup"] = new HLookup();
     Functions["vlookup"] = new VLookup();
     Functions["lookup"] = new Lookup();
     Functions["match"] = new Match();
     Functions["row"] = new Row(){SkipArgumentEvaluation = true};
     Functions["rows"] = new Rows(){SkipArgumentEvaluation = true};
     Functions["column"] = new Column(){SkipArgumentEvaluation = true};
     Functions["columns"] = new Columns(){SkipArgumentEvaluation = true};
     Functions["choose"] = new Choose();
     Functions["index"] = new Index();
     Functions["indirect"] = new Indirect();
     Functions["offset"] = new Offset(){SkipArgumentEvaluation = true};
     // Date
     Functions["date"] = new Date();
     Functions["today"] = new Today();
     Functions["now"] = new Now();
     Functions["day"] = new Day();
     Functions["month"] = new Month();
     Functions["year"] = new Year();
     Functions["time"] = new Time();
     Functions["hour"] = new Hour();
     Functions["minute"] = new Minute();
     Functions["second"] = new Second();
     Functions["weeknum"] = new Weeknum();
     Functions["weekday"] = new Weekday();
     Functions["days360"] = new Days360();
     Functions["yearfrac"] = new Yearfrac();
     Functions["edate"] = new Edate();
     Functions["eomonth"] = new Eomonth();
     Functions["isoweeknum"] = new IsoWeekNum();
     Functions["workday"] = new Workday();
     // Database
     Functions["dget"] = new Dget();
     Functions["dcount"] = new Dcount();
     Functions["dcounta"] = new DcountA();
     Functions["dmax"] = new Dmax();
     Functions["dmin"] = new Dmin();
     Functions["dsum"] = new Dsum();
     Functions["daverage"] = new Daverage();
     Functions["dvar"] = new Dvar();
     Functions["dvarp"] = new Dvarp();
 }
Exemplo n.º 4
0
 public void SumIfNotEqualToNull()
 {
     _worksheet.Cells["A1"].Value = null;
     _worksheet.Cells["A2"].Value = string.Empty;
     _worksheet.Cells["A3"].Value = "Not Empty";
     _worksheet.Cells["B1"].Value = 1d;
     _worksheet.Cells["B2"].Value = 3d;
     _worksheet.Cells["B3"].Value = 5d;
     var func = new SumIf();
     IRangeInfo range1 = _provider.GetRange(_worksheet.Name, 1, 1, 3, 1);
     IRangeInfo range2 = _provider.GetRange(_worksheet.Name, 1, 2, 3, 2);
     var args = FunctionsHelper.CreateArgs(range1, "<>", range2);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(8d, result.Result);
 }
Exemplo n.º 5
0
 public void SumIfShouldThrowIfCriteriaIsLargerThan255Chars()
 {
     var longString = "a";
     for (var x = 0; x < 256; x++) { longString = string.Concat(longString, "a"); }
     var func = new SumIf();
     var args = FunctionsHelper.CreateArgs(FunctionsHelper.CreateArgs(3, 4, 5), longString, (FunctionsHelper.CreateArgs(3, 2, 1)));
     var result = func.Execute(args, _parsingContext);
 }
Exemplo n.º 6
0
 public void SumIfShouldCalculateWithExpression()
 {
     var func = new SumIf();
     var args = FunctionsHelper.CreateArgs(FunctionsHelper.CreateArgs(3, 4, 5), ">3");
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(9d, result.Result);
 }
Exemplo n.º 7
0
 public void SumIfShouldCalculateMatchingValuesOnly()
 {
     var func = new SumIf();
     var args = FunctionsHelper.CreateArgs(FunctionsHelper.CreateArgs(3, 4, 5), "4");
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(4d, result.Result);
 }