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

Freezing excel rows doesn't work in version 2.10.0 #680

Closed
Martijn85 opened this issue Feb 12, 2020 · 8 comments · Fixed by #690 · May be fixed by #676
Closed

Freezing excel rows doesn't work in version 2.10.0 #680

Martijn85 opened this issue Feb 12, 2020 · 8 comments · Fixed by #690 · May be fixed by #676

Comments

@Martijn85
Copy link

@Martijn85 Martijn85 commented Feb 12, 2020

After updating to version 2.10.0 from 2.9.1 the option to freeze rows using a pane results in a corrupt excel file.

.NET Framework 4.7.2
DocumentFormat.OpenXml 2.10.0

SheetView sheetView = worksheet.SheetViews.Elements<SheetView>().FirstOrDefault();
Selection selection = sheetView.GetFirstChild<Selection>();
Pane freezePane = new Pane()
{
      VerticalSplit = topRows,
      TopLeftCell = $@"A{topRows + 1}",
      ActivePane = PaneValues.BottomLeft,
      State = PaneStateValues.Frozen
};
sheetView.InsertBefore(freezePane, selection);

Observed

Excel file can no longer be opened.

Expected

The excel file to work like version 2.9.1

@Martijn85

This comment has been minimized.

Copy link
Author

@Martijn85 Martijn85 commented Feb 12, 2020

The reason appears to be that in version 2.10.0 the SheetViews is added after the SheetData element. Managed to solve the problem by forcing this in code.

SheetData sheetData = worksheet.Elements<SheetData>().FirstOrDefault();
worksheet.InsertBefore<SheetViews>(new SheetViews(), sheetData);

This was however not required in version 2.9.1

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 19, 2020

Thanks for the report. I'll take a look

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 19, 2020

@Martijn85 Can you show a minimal repro? I'm interested in what you had in 2.9.1 vs what you have in 2.10.0. The issue you said is probably it, but I don't see how you added the SheetViews in 2.9.1.

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 19, 2020

So, I may have a repro. Let me know if this is different what you're seeing:

[Fact]
public void Test1()
{
    var ws = new Worksheet();

    ws.AppendChild(new SheetData());
    ws.SheetViews = new SheetViews();

    Assert.Collection(
        ws.ChildElements,
        e => Assert.IsType<SheetViews>(e),
        e => Assert.IsType<SheetData>(e));
}

This worked in 2.9.1, but not 2.10.0.

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 19, 2020

So, this is fixed in a PR already open. The problem was that as part of a refactoring 2.9.0->2.10.0, I tried to remove redundant data and as part of that, elements that were not statically typed were all of a sudden unknown to the parent element. This made it so that insertion got messed up. The PR I've linked to is much smarter about identifying where to insert an element.

@Martijn85

This comment has been minimized.

Copy link
Author

@Martijn85 Martijn85 commented Feb 20, 2020

Thank you for your response Taylor.
This indeed appears to be the same problem. Your test also works in 2.9.1 and no in 2.10.0

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 20, 2020

Cool - sorry about that! Definitely a part of a bigger problem that #676 is trying to address

@twsouthwick

This comment has been minimized.

Copy link
Collaborator

@twsouthwick twsouthwick commented Feb 26, 2020

I'm looking at cutting a 2.10.1 release to get this fix out quicker than a 2.11 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.