Freeze frames in OpenXML SDK 2.0 for Excel document

I create an Excel workbook using OpenXml and follow the examples http://msdn.microsoft.com/en-us/library/cc850837.aspx

It would be very helpful if I could freeze the top panels, but I cannot find a way to do this. I understand that I can do this if I use http://closedxml.codeplex.com/ , but now I would like to stick with the OpenXML SDK

Any ideas?

+5
source share
2 answers

I tried to solve the same problem and ended up opening a tool to improve the performance of the Open XML SDK 2.0 and using the function Compare Files...to compare two tables: one with and without frozen panels.

When I did this, I got code that looked basically like this:

WorkbookPart wbp = doc.WorkbookPart;
WorksheetPart wsp = wbp.WorksheetParts.First();

SheetViews sheetviews = wsp.Worksheet.GetFirstChild<SheetViews>();
SheetView sv = sheetviews.GetFirstChild<SheetView>();
Selection selection = sv.GetFirstChild<Selection>();
Pane pane = new Pane(){ VerticalSplit = 1D, TopLeftCell = "A2", ActivePane = PaneValues.BottomLeft, State = PaneStateValues.Frozen };
sv.InsertBefore(pane,selection);
selection.Pane = PaneValues.BottomLeft;

I added this to my program and it seems to have done the trick.

+9
source

You can also add Selection:

WorkbookPart wbp = doc.WorkbookPart;
WorksheetPart wsp = wbp.WorksheetParts.First(); 

SheetViews sheetViews = wsp.Worksheet.GetFirstChild<SheetViews>();
SheetView sheetView = sheetViews.GetFirstChild<SheetView>();

Selection selection1 = new Selection() { Pane = PaneValues.BottomLeft };

Pane pane1 = new Pane() { VerticalSplit = 1D, TopLeftCell = "A2", ActivePane = PaneValues.BottomLeft, State = PaneStateValues.Frozen };

sheetView.Append(pane1);
sheetView.Append(selection1);
+7
source

All Articles