Cómo Seleccionar un Rango en Excel Usando C# | IronXL

How to Select Range

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronXL provides a convenient way to select and manipulate ranges within an Excel Worksheet without using Office Interop.

Quickstart: Selecting a Cell Range in IronXL in One Line

Use a single call to GetRange on an IronXL worksheet to grab a rectangular range like "A1:C3"—no loops, no fuss. It’s the fastest way to start manipulating multiple cells at once.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    var range = workSheet.GetRange("A1:C3");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer


Select Range Example

With IronXL, you can perform various operations on selected ranges, such as sorting, calculations, and aggregations.

Por favor notaWhen applying methods that modify or move cell values, the affected range, row, or column will update its values accordingly.

ConsejosIronXL allows us to combine more than one IronXL.Ranges.Range using the '+' operator.

Select Range

To select a range from cell A2 to B8, you can use the following code:

:path=/static-assets/excel/content-code-examples/how-to/select-range-range.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get range from worksheet
var range = workSheet["A2:B8"];
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("sample.xls")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Get range from worksheet
Private range = workSheet("A2:B8")
$vbLabelText   $csharpLabel
Select Range

Select Row

To select the 4th row, you can use the GetRow(3) method with zero-based indexing. This will include all cells in the 4th row, even if some corresponding cells in other rows are empty.

:path=/static-assets/excel/content-code-examples/how-to/select-range-row.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get row from worksheet
var row = workSheet.GetRow(3);
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("sample.xls")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Get row from worksheet
Private row = workSheet.GetRow(3)
$vbLabelText   $csharpLabel
Select Row

Select Column

To select column C, you can use the GetColumn(2) method or specify the range address as workSheet ["C:C"]. Like the GetRow method, it will include all relevant cells, whether they are filled in the specified column or not.

:path=/static-assets/excel/content-code-examples/how-to/select-range-column.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get column from worksheet
var column = workSheet.GetColumn(2);
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("sample.xls")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Get column from worksheet
Private column = workSheet.GetColumn(2)
$vbLabelText   $csharpLabel
Select Column

ConsejosAll the row and column index positions adhere to zero-based indexing.

Combine Ranges

IronXL provides the flexibility to combine multiple IronXL.Ranges.Range objects using the '+' operator. By using the '+' operator, you can easily concatenate or merge ranges together to create a new range.

Por favor notaCombining rows and columns directly using the '+' operator is not supported.

Combining ranges will modify the original range. In the code snippet below, the variable range will be modified to include the combined ranges.

:path=/static-assets/excel/content-code-examples/how-to/select-range-combine-range.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get range from worksheet
var range = workSheet["A2:B2"];

// Combine two ranges
var combinedRange = range + workSheet["A5:B5"];
Imports IronXL
Imports System.Linq

Private workBook As WorkBook = WorkBook.Load("sample.xls")
Private workSheet As WorkSheet = workBook.WorkSheets.First()

' Get range from worksheet
Private range = workSheet("A2:B2")

' Combine two ranges
Private combinedRange = range + workSheet("A5:B5")
$vbLabelText   $csharpLabel

Preguntas Frecuentes

¿Cómo selecciono un rango de celdas en Excel usando IronXL?

Puedes seleccionar un rango de celdas en Excel usando IronXL referenciando directamente el rango con workSheet["A2:B8"] después de obtener un objeto WorkSheet.

¿Cuál es el método para seleccionar toda una fila en IronXL?

Puedes seleccionar toda una fila en IronXL usando el método GetRow con indexación basada en cero. Por ejemplo, para seleccionar la 4ª fila, usa worksheet.GetRow(3).

¿Cómo puedo seleccionar una columna en una hoja de Excel usando IronXL?

Para seleccionar una columna en IronXL, usa el método GetColumn con indexación basada en cero, como worksheet.GetColumn(2) para la columna C, o especifica el rango como worksheet["C:C"].

¿Es posible combinar múltiples rangos en IronXL?

Sí, puedes combinar múltiples objetos de IronXL.Ranges.Range usando el operador '+' para fusionar dos o más rangos en un nuevo rango.

¿Requiere IronXL el uso de Office Interop para seleccionar y manipular rangos de Excel?

No, IronXL permite seleccionar y manipular rangos de Excel sin la necesidad de Office Interop, lo que lo convierte en una opción más simple y eficiente para trabajar con archivos de Excel.

¿Qué operaciones puedo realizar en un rango seleccionado en IronXL?

Una vez que un rango está seleccionado en IronXL, puedes realizar operaciones como ordenar, cálculos y agregaciones. Cualquier modificación a los valores de celdas dentro de estos rangos actualizará dinámicamente la hoja de cálculo.

¿Cómo afecta la combinación de rangos al rango original en IronXL?

La combinación de rangos con el operador '+' en IronXL modifica el rango original para incluir los rangos combinados, lo que permite una manipulación sin interrupciones de conjuntos de datos más grandes.

¿Qué sistema de indexación usa IronXL para filas y columnas?

IronXL utiliza indexación basada en cero tanto para filas como para columnas, lo que significa que el índice comienza en 0.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado