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

Conditional formatting breaks in template with multiple tables one below other #355

Open
pledominykas opened this issue Apr 30, 2024 · 1 comment

Comments

@pledominykas
Copy link

Conditional formatting breaks when used inside template with multiple tables one after the other.

Template broken:
repro-template-broken.xlsx

Template working:
repro-template-working.xlsx

Code:

using ClosedXML.Report;

var data = new
{
    Directors = new[]
    {
        new { Director = "Steven Spielberg", Movie = "Jaws" },
        new { Director = "Quentin Tarantino", Movie = "Pulp Fiction" },
        new { Director = "Steven Spielberg", Movie = "E.T." },
        new { Director = "Quentin Tarantino", Movie = "" },
        new { Director = "Steven Spielberg", Movie = "Jurassic Park" },
        new { Director = "Quentin Tarantino", Movie = "" },
        new { Director = "Steven Spielberg", Movie = "Indiana Jones" },
    },
    Genres = new[]
    {
        new { Movie = "Jaws", Genre = "Thriller" },
        new { Movie = "Pulp Fiction", Genre = "" },
        new { Movie = "E.T.", Genre = "Sci-Fi" },
        new { Movie = "Kill Bill", Genre = "" },
        new { Movie = "Jurassic Park", Genre = "Sci-Fi" },
        new { Movie = "Reservoir Dogs", Genre = "Thriller" },
        new { Movie = "Indiana Jones", Genre = "" },
        new { Movie = "E.T.", Genre = "Family" },
        new { Movie = "Jaws", Genre = "Horror" },
    },
    Actors = new[]
    {
        new { Movie = "Jaws", Actor = "Roy Scheider" },
        new { Movie = "Pulp Fiction", Actor = "John Travolta" },
        new { Movie = "E.T.", Actor = "" },
        new { Movie = "E.T.", Actor = "Henry Thomas" },
        new { Movie = "Kill Bill", Actor = "" }
    },
};

void GenerateWithClosedXML()
{
    const string outputFile = "./output.xlsx";
    var template = new XLTemplate(@"./repro-template-broken.xlsx");
    // var template = new XLTemplate(@"./repro-template-working.xlsx");

    template.AddVariable(data);
    template.Generate();

    template.SaveAs(outputFile);
}

GenerateWithClosedXML();

Repro steps:

  1. Run attached code
  2. Observe conditional formatting is applied in wrong place

Results:
Template should color the cell in red if value is empty:
image

However after generating the output conditional formatting breaks for the second table:
image

Note: if the gap between tables is more than 4 lines conditional formatting is applied correctly (as seen in repro-template-working.xlsx)

@pikami
Copy link

pikami commented Jun 10, 2024

This might be related to an issue in the ClosedXML package: ClosedXML/ClosedXML#686

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants