Aspose.Words.Examples.CSharp.Programming_Documents.Working_With_Document.AddRemoveColumn.Column.InsertColumnBefore C# (CSharp) Method

InsertColumnBefore() public method

Inserts a brand new column before this column into the table.
public InsertColumnBefore ( ) : Column
return Column
            public Column InsertColumnBefore()
            {
                Cell[] columnCells = Cells;

                if (columnCells.Length == 0)
                    throw new ArgumentException("Column must not be empty");

                // Create a clone of this column.
                foreach (Cell cell in columnCells)
                    cell.ParentRow.InsertBefore(cell.Clone(false), cell);

                // This is the new column.
                Column column = new Column(columnCells[0].ParentRow.ParentTable, mColumnIndex);

                // We want to make sure that the cells are all valid to work with (have at least one paragraph).
                foreach (Cell cell in column.Cells)
                    cell.EnsureMinimum();

                // Increase the index which this column represents since there is now one extra column infront.
                mColumnIndex++;

                return column;
            }