Ejemplo n.º 1
0
        /// <summary>
        /// Freezes top rows.
        /// </summary>
        /// <param name="workSheet">Source workSheet.</param>
        /// <param name="rowNum">Number or rows to freeze.</param>
        /// <returns>The same <paramref name="workSheet"/> instance.</returns>
        public static Worksheet FreezeTopRow(this Worksheet workSheet, int rowNum = 1)
        {
            SheetViews sheetViews = workSheet.GetOrCreateSheetViews();

            SheetView sheetView = sheetViews.GetFirstChild <SheetView>();

            // the freeze pane
            Pane pane = new Pane
            {
                VerticalSplit = rowNum,
                TopLeftCell   = $"A{rowNum + 1}",
                ActivePane    = PaneValues.BottomLeft,
                State         = PaneStateValues.Frozen,
            };

            Selection selection = new Selection
            {
                Pane                 = PaneValues.BottomLeft,
                ActiveCell           = pane.TopLeftCell,
                SequenceOfReferences = new ListValue <StringValue>()
                {
                    InnerText = pane.TopLeftCell
                },
            };

            sheetView.AppendChild(pane);
            sheetView.AppendChild(selection);

            return(workSheet);
        }
Ejemplo n.º 2
0
        private void AppendSheetViews(WorksheetPart worksheetPart, bool hasKey)
        {
            SheetViews sheetViews = worksheetPart.Worksheet.AppendChild(new SheetViews());
            SheetView  sheetView  = sheetViews.AppendChild(new SheetView()
            {
                WorkbookViewId = 0U
            });

            Pane pane = new Pane()
            {
                VerticalSplit   = 4D,
                HorizontalSplit = hasKey ? 2D : 1D,
                TopLeftCell     = hasKey ? "C5" : "B5",
                ActivePane      = PaneValues.BottomRight,
                State           = PaneStateValues.Frozen
            };

            sheetView.AppendChild(pane);
        }