Back to Devexpress

How to: Access a Row or Column

officefileapi-12086-spreadsheet-document-api-examples-rows-and-columns-how-to-access-a-row-or-column.md

latest3.0 KB
Original Source

How to: Access a Row or Column

  • Sep 19, 2023
  • 2 minutes to read

Rows

This example demonstrates how to access rows in a worksheet. Use the Worksheet.Rows property to get a collection of rows contained in a worksheet (the RowCollection object). To get an individual row by its index (zero-based) or heading (“1”, “2”, “3”, etc.), use the RowCollection.Item property.

csharp
using DevExpress.Spreadsheet;
// ...

Workbook workbook = new Workbook();

// Access a collection of rows.
RowCollection rows = workbook.Worksheets[0].Rows;

// Access the first row by its index in the collection of rows.
Row firstRow_byIndex = rows[0];

// Access the first row by its unique name.
Row firstRow_byName = rows["1"];
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As New Workbook()

' Access a collection of rows.
Dim rows As RowCollection = workbook.Worksheets(0).Rows

' Access the first row by its index in the collection of rows.
Dim firstRow_byIndex As Row = rows(0)

' Access the first row by its unique name.
Dim firstRow_byName As Row = rows("1")

Columns

This example demonstrates how to access columns in a worksheet. Use the Worksheet.Columns property to get a collection of columns contained in a worksheet (the ColumnCollection object). To get an individual column by its index (zero-based) or heading (“A”, “B”, “C”, etc.), use the ColumnCollection.Item property.

csharp
using DevExpress.Spreadsheet;
// ...

Workbook workbook = new Workbook();

// Access a collection of columns.
ColumnCollection columns = workbook.Worksheets[0].Columns;

// Access the first column by its index in the collection of columns.
Column firstColumn_byIndex = columns[0];

// Access the first column by its unique name.
Column firstColumn_byName = columns["A"];
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As New Workbook()

' Access a collection of columns.
Dim columns As ColumnCollection = workbook.Worksheets(0).Columns

' Access the first column by its index in the collection of columns.
Dim firstColumn_byIndex As Column = columns(0)

' Access the first column by its unique name.
Dim firstColumn_byName As Column = columns("A")

The image below shows row and column indexes and headings in a worksheet, when a workbook is opened in Microsoft® Excel®.

See Also

Rows and Columns in Spreadsheet Documents