Beispiel #1
0
        /// <summary>
        /// Create a CellAddress from a Reference like A1
        /// </summary>
        /// <param name="cellAddress"></param>
        public CellAddress(string cellAddress)
        {
            var cr = CellAddressHelper.ReferenceToColRow(cellAddress);

            Column = cr.Item1;
            Row    = cr.Item2;
        }
Beispiel #2
0
        /// <summary>
        /// Freezes rows at the top and columns on the left.
        /// </summary>
        /// <param name="rows">The number of rows to freeze.</param>
        /// <param name="columns">The number of columns to freeze.</param>
        /// <param name="activePane">The pane that's selected in the sheet. Leave null to automatically determine this.</param>
        public void FreezeTopLeft(int rows, int columns, Panes?activePane = null)
        {
            // TODO: Eventually, support more SheetView functionality, right now, keep it simple.
            if (_sheetViews != null)
            {
                throw new InvalidOperationException("You have already frozen rows and/or columns on this Worksheet.");
            }

            if (rows < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(rows), "Rows cannot be negative.");
            }

            if (columns < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(columns), "Columns cannot be negative.");
            }

            if (columns == 0 && rows == 0)
            {
                return;
            }

            if (!activePane.HasValue)
            {
                if (columns == 0)
                {
                    activePane = Panes.BottomLeft;
                }
                else if (rows == 0)
                {
                    activePane = Panes.TopRight;
                }
                else
                {
                    activePane = Panes.BottomRight;
                }
            }

            var sheetView = new SheetView
            {
                Pane = new Pane
                {
                    ActivePane  = activePane.Value,
                    XSplit      = columns > 0 ? (int?)columns : null,
                    YSplit      = rows > 0 ? (int?)rows : null,
                    TopLeftCell = CellAddressHelper.ColRowToReference(columns, rows),
                    State       = PaneState.Frozen
                }
            };

            sheetView.AddSelection(new Selection {
                ActivePane = activePane.Value
            });
            AddSheetView(sheetView);
        }
Beispiel #3
0
 /// <summary>
 /// Convert this CellAddress into a Cell Reference, e.g. A1 for [0,0]
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(CellAddressHelper.ColRowToReference(Column, Row));
 }
 /// <summary>
 /// Insert a manual page break to the left of the column specified by the cell address (e.g., B5)
 /// </summary>
 /// <param name="sheet"></param>
 /// <param name="cellAddress"></param>
 public static void InsertManualPageBreakAfterColumn(this Worksheet sheet, string cellAddress)
 {
     CellAddressHelper.ReferenceToColRow(cellAddress, out int row, out int col);
     sheet.InsertManualPageBreakAfterColumn(col + 1);
 }