EPPlus
EPPlus copied to clipboard
IFERROR not working properly when containing a function that returns an error
The IFERROR function doesn't seem to work properly in certain situations.
For example, if I write the following formula without first defining the name MyName1, I'll (correctly) get a #NAME? error when recalculating.
IF(MyName1=1,"A","B")
If I put this formula inside an IFERROR function, the #NAME? error should be suppressed and the second argument returned - in this case the string "error".
IFERROR(IF(MyName1=1,"A","B"), "error")
However, EPPlus calculates this cell as having the value #VALUE!. I think this is a bug.
Unit Test
[TestMethod]
public void IfError_InnerFunctionReturningError()
{
using (var pck = new ExcelPackage())
{
var sheet1 = pck.Workbook.Worksheets.Add("Sheet1");
sheet1.Cells["C3"].Formula = "IFERROR(IF(NameDoesntExist=1,\"A\",\"B\"),\"error\")";
sheet1.Calculate();
Assert.IsFalse(sheet1.Cells["C3"].Value is ExcelErrorValue);
Assert.AreEqual("error", sheet1.Cells["C3"].GetValue<string>());
}
}
Thanks, We'll have a look at this.
This error occured due to invalid handling of error values in the IF function. It is now fixed in our develop branch/nuget feed and will be included in the next version.
Thanks!
Released in 6.0.7