NativeExcel for .NET Developer's Reference

Referring to Columns

Use the Columns property to work with columns. This property returns an IRangeColumns interface which represents the columns of the range.

Example

In the following example, Columns[1] returns column one of used range on Sheet1.

[C#]
book.Worksheets[1].UsedRange.Columns[1].Font.Bold = true;
        
[Visual Basic]
book.Worksheets(1).UsedRange.Columns(1).Font.Bold = True
        
[C++]
book->Worksheets->Item[1]->UsedRange->Columns->Item[1]->Font->Bold = true;
        
This example clears contents of column three in the range B5:F19.
[C#]
book.Worksheets[1].Range["B5:F19"].Columns[3].ClearContents();
        
[Visual Basic]
book.Worksheets(1).Range("B5:F19").Columns(3).ClearContents()
        
[C++]
book->Worksheets->Item[1]->Range->Item[S"B5:F19"]->Columns->Item[3]->ClearContents();
        
This example merges the first column of range B2:C5.
[C#]
book.Worksheets[1].Range["B2:C5"].Columns[1].Merge();
        
[Visual Basic]
book.Worksheets(1).Range("B2:C5").Columns(1).Merge()
        
[C++]
book->Worksheets->Item[1]->Range->Item[S"B2:C5"]->Columns->Item[1]->Merge();