ColumnCollection.Insert(Int32) Method
Inserts a new column into the worksheet at the specified position.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
index | Int32 | A zero-based index of the column to insert. If the index is negative or exceeds the last available index (16383), an exception occurs. |
Remarks
The number of columns in a worksheet does not change—16,384. When you add new columns, other columns in the worksheet are shifted to the right, and an equivalent number of columns at the end of the worksheet is removed.
Example
This example demonstrates how to insert new columns into a worksheet.
- Use the Column.Insert method to add a new column to the left of the current column.
- Call the ColumnCollection.Insert method of the Worksheet.Columns collection to insert a column at the specified position or add multiple columns at once.
- To insert empty columns to the left of the specified cell range, use the Worksheet.InsertCells method with the InsertCellsMode.EntireColumn enumeration member passed as a parameter. This method inserts the same number of columns as the specified cell range contains.
Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you add multiple columns to a document.
// Insert a new column C.
worksheet.Columns["C"].Insert();
// Insert a new column into the worksheet at the 5th position.
worksheet.Columns.Insert(4);
// Insert three columns into the worksheet at the 7th position.
worksheet.Columns.Insert(6, 3);
// Insert two columns to the left of the "L15:M16" cell range.
worksheet.InsertCells(worksheet.Range["L15:M16"], InsertCellsMode.EntireColumn);
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(Int32) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.