Select Excel Range

IronXL allows us to easily select and work with ranges in any Excel WorkSheet. The code below demonstrates how ranges, rows, and columns can be easily selected. With IronXL, it is possible to apply further sorting or calculations to this collection of data using methods such as SortAscending(), SortDescending(), Sum(), Max(), Min(), and Avg(). However, be mindful that when applying methods that modify or move the value of a cell, the affected range, row, and column will also update their values accordingly.

Range

To select a range from A2 to A8, use var range = sheet["A2:A8"].

Row

To select row 1, use the method GetRow(0). The indexing follows zero-based numbering. The range of cells will be determined by the union of the populated cells of all the rows, including row 1 itself.

Column

To select column A, use the method GetColumn(0) or assign the range address as sheet["A:A"]. The range of cells will be determined by the union of the populated cells of all columns, including column A itself.

How to select Excel Range in C#

// Step 1: Install C# library to select Excel range from https://nuget.org/packages/IronXL.Excel/

// Step 2: Load an existing or generate a new Excel workbook
var workbook = IronXL.WorkBook.Load("example.xlsx");

// Step 3: Select the targeted worksheet from the workbook
var sheet = workbook.WorkSheets.First();

// Step 4: Use sheet["A2:A8"] to select range from A2 to A8
var range = sheet["A2:A8"];

// Step 5: Use GetColumn and GetRow methods to select individual columns and rows
// Example for selecting a column
var column = sheet.GetColumn(0); // Selects column A

// Example for selecting a row
var row = sheet.GetRow(0); // Selects row 1
// Step 1: Install C# library to select Excel range from https://nuget.org/packages/IronXL.Excel/

// Step 2: Load an existing or generate a new Excel workbook
var workbook = IronXL.WorkBook.Load("example.xlsx");

// Step 3: Select the targeted worksheet from the workbook
var sheet = workbook.WorkSheets.First();

// Step 4: Use sheet["A2:A8"] to select range from A2 to A8
var range = sheet["A2:A8"];

// Step 5: Use GetColumn and GetRow methods to select individual columns and rows
// Example for selecting a column
var column = sheet.GetColumn(0); // Selects column A

// Example for selecting a row
var row = sheet.GetRow(0); // Selects row 1
' Step 1: Install C# library to select Excel range from https://nuget.org/packages/IronXL.Excel/

' Step 2: Load an existing or generate a new Excel workbook
Dim workbook = IronXL.WorkBook.Load("example.xlsx")

' Step 3: Select the targeted worksheet from the workbook
Dim sheet = workbook.WorkSheets.First()

' Step 4: Use sheet["A2:A8"] to select range from A2 to A8
Dim range = sheet("A2:A8")

' Step 5: Use GetColumn and GetRow methods to select individual columns and rows
' Example for selecting a column
Dim column = sheet.GetColumn(0) ' Selects column A

' Example for selecting a row
Dim row = sheet.GetRow(0) ' Selects row 1
$vbLabelText   $csharpLabel
  1. Install C# library to select Excel range
  2. Load an existing or generate a new Excel workbook
  3. Select the targeted worksheet from the workbook
  4. Use sheet["A2:A8"] to select a range from A2 to A8
  5. Use GetColumn and GetRow methods to select individual columns and rows