IXlSheet.CreateColumn(Int32) Method

Creates a new column in the worksheet with the specified index.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v21.2.Core.dll


IXlColumn CreateColumn(
    int columnIndex


Name Type Description
columnIndex Int32

An integer specifying the zero-based index of the created column. If it is negative or exceeds the last available index, an exception is raised.


Type Description

An IXlColumn object that is the newly created column.


Columns in a worksheet should be created prior to rows and cells. If you try to create a column after or during the row generation, an InvalidOperationException exception will be thrown.


The example below demonstrates how to create and modify a column in a worksheet. To do this, use the IXlSheet.CreateColumn method. To specify where a created column should be located in a worksheet, pass a zero-based column index to the method as a parameter.

// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet())
    // Create the column "A" and set its width to 100 pixels.
    using (IXlColumn column = sheet.CreateColumn())
        column.WidthInPixels = 100;

    // Create the column D and set its width to 24.5 characters.
    using (IXlColumn column = sheet.CreateColumn(3))
        column.WidthInCharacters = 24.5f;

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateColumn(Int32) method.


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.

See Also