Skip to content

Commit c5da781

Browse files
authored
Fixed bug in FILTER function where third parameter should be able to handle error value as input. #2239 (#2244)
1 parent 1abbcf3 commit c5da781

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

  • src
    • EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup
    • EPPlus/FormulaParsing/Excel/Functions/RefAndLookup

src/EPPlus/FormulaParsing/Excel/Functions/RefAndLookup/Filter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Date Author Change
1414
using System.Collections.Generic;
1515
using System.Linq;
1616
using System.Text;
17+
using OfficeOpenXml.Export.HtmlExport;
1718
using OfficeOpenXml.FormulaParsing.Excel.Functions.MathFunctions;
1819
using OfficeOpenXml.FormulaParsing.Excel.Functions.Metadata;
1920
using OfficeOpenXml.FormulaParsing.Exceptions;
@@ -184,5 +185,14 @@ public override string NamespacePrefix
184185
/// If the function is allowed in a pivot table calculated field
185186
/// </summary>
186187
public override bool IsAllowedInCalculatedPivotTableField => false;
187-
}
188+
189+
public override ExcelFunctionParametersInfo ParametersInfo => new ExcelFunctionParametersInfo(new Func<int, FunctionParameterInformation>((argumentIndex) =>
190+
{
191+
if (argumentIndex == 2)
192+
{
193+
return FunctionParameterInformation.IgnoreErrorInPreExecute;
194+
}
195+
return FunctionParameterInformation.Normal;
196+
}));
197+
}
188198
}

src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/FilterTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,21 @@ public void ShouldFilterOnColumn()
6767
Assert.AreEqual(4, _ws.Cells["D2"].Value);
6868
Assert.AreEqual(1, _ws.Cells["D3"].Value);
6969
}
70+
71+
[TestMethod]
72+
public void FilterShouldHandleNAAsIfEmptyValue()
73+
{
74+
using (var package = new ExcelPackage())
75+
{
76+
var s = package.Workbook.Worksheets.Add("test");
77+
s.Cells["A1"].Value = "Joe";
78+
s.Cells["A2"].Value = "Anna";
79+
s.Cells["B1"].Value = 1;
80+
s.Cells["B2"].Value = 2;
81+
s.Cells["C1"].Formula = "FILTER(A1:A2, B1:B2 =1, NA())";
82+
s.Calculate();
83+
Assert.AreEqual("Joe", s.Cells["C1"].Value);
84+
}
85+
}
7086
}
7187
}

0 commit comments

Comments
 (0)