EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

IFERROR not working properly when containing a function that returns an error

Open craigbrown opened this issue 3 years ago • 3 comments
trafficstars

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>());
    }
}

craigbrown avatar Jul 28 '22 13:07 craigbrown

Thanks, We'll have a look at this.

JanKallman avatar Aug 01 '22 07:08 JanKallman

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.

swmal avatar Aug 03 '22 10:08 swmal

Thanks!

craigbrown avatar Aug 04 '22 22:08 craigbrown

Released in 6.0.7

swmal avatar Aug 31 '22 07:08 swmal