Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPPlus differs from Excel with three specific formula conditions #666

Closed
colbybhearn opened this issue Jun 9, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@colbybhearn
Copy link
Contributor

colbybhearn commented Jun 9, 2022

I found EPPlus differing from Excel when it encounters a single formula which

  1. uses @Indirect to access a decimal number, and
  2. the indirectly accessed decimal number is formatted as text, and
  3. an integer is added (outside the @indirect function)

Example: =@INDIRECT("Link_"&A1,TRUE)+2

All three aspects seem required, as I tested these permutations:

  • using @indirect to access a number formatted as text works as expected
  • adding some integer to an indirect accessed number formatted as a number works as expected
  • adding some integer to a number formatted as text works as expected

Can you take a look at the attached spreadsheet and sample code? It replicates A) the more complicated scenario in which this behavior was found and B) the simplest, minimal example I could come up with.

Here's the sample code I used with the attached file.

string filepath = @"C:\IndirectSample.xlsx";
ExcelPackage.LicenseContext = LicenseContext.Commercial;
ExcelCalculationOption o = new ExcelCalculationOption();
o.AllowCircularReferences = false;
o.PrecisionAndRoundingStrategy = PrecisionAndRoundingStrategy.Excel;
using (var package = new ExcelPackage(new FileInfo(filepath)))
{
    try
    {
        package.Workbook.Calculate(o);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C2"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C3"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C4"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C5"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C6"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C7"].Value);
        Trace.WriteLine(package.Workbook.Worksheets["ref"].Cells["C8"].Value);                    
    }
    catch (Exception e)
    {
    }
}

IndirectSample.xlsx

I pulled down commit 6854ceb to recreate this issue.

Thank you for your time and being just generally awesome.

@swmal
Copy link
Contributor

swmal commented Jun 9, 2022

Thanks Colby, your error reports are awesome too! I'll get back to you.

@swmal swmal self-assigned this Jun 10, 2022
@swmal swmal added the bug Something isn't working label Jun 10, 2022
swmal added a commit that referenced this issue Jun 10, 2022
swmal added a commit that referenced this issue Jun 10, 2022
@swmal
Copy link
Contributor

swmal commented Jun 10, 2022

This should be solved now, will be included in next version of both v 5 and 6.

@swmal swmal closed this as completed Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants