Back to Devexpress

Column.Insert() Method

officefileapi-devexpress-dot-spreadsheet-dot-column-07104b35.md

latest6.8 KB
Original Source

Column.Insert() Method

Inserts a new column into the worksheet.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Insert()
vb
Sub Insert

Remarks

Use the Insert method to add a new column to the left of the current column. To add more than one column, use the ColumnCollection.Insert method.

Note

The number of columns in a worksheet is unchanged - 16,384. When you add new columns, the equivalent number of columns at the end are automatically removed from the worksheet.

To copy data (for example, values, formulas, formatting, etc.) from one column to another one, use the CellRange.CopyFrom method. For details, see the How to: Copy a Row or Column example.

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.

View Example

csharp
// 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);
vb
' 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)

The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert() 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.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.cs#L42

csharp
// Insert a new column C.
worksheet.Columns["C"].Insert();

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.cs#L43

csharp
// Insert a new column C.
worksheet.Columns["C"].Insert();

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L44

csharp
// Insert column "C".
worksheet.Columns["C"].Insert();

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.vb#L46

vb
' Insert a new column C.
worksheet.Columns("C").Insert()

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.vb#L46

vb
' Insert a new column C.
worksheet.Columns("C").Insert()

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L38

vb
' Insert column "C".
worksheet.Columns("C").Insert()
' Insert column "E".

See Also

Insert

InsertCells

Rows and Columns in Spreadsheet Documents

Column Interface

Column Members

DevExpress.Spreadsheet Namespace