Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/FormulaParsing/Excel/Functions/Math/CountBlank.cs

Last change on this file was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 1.0 KB
Line 
1using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
2using OfficeOpenXml.FormulaParsing.ExpressionGraph;
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using System.Text;
7
8namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Math
9{
10    public class CountBlank : ExcelFunction
11    {
12        public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context)
13        {
14            ValidateArguments(arguments, 1);
15            var arg = arguments.First();
16            if(!arg.IsExcelRange)throw new InvalidOperationException("CountBlank only support ranges as arguments");
17            var result = arg.ValueAsRangeInfo.GetNCells();
18            foreach (var cell in arg.ValueAsRangeInfo)
19            {
20                if (!(cell.Value == null || cell.Value == string.Empty))
21                {
22                    result--;
23                }
24            }
25            return CreateResult(result, DataType.Integer);
26        }
27    }
28}
Note: See TracBrowser for help on using the repository browser.