How to: Access a Cell in a Worksheet
- 3 minutes to read
This example demonstrates several ways to access individual cells.
- By row and column indexes of a cell via the Worksheet.Item property.
- By a cell reference (for example, A1, B2, etc.) or by row and column indexes from the worksheet’s collection of cells. Use the CellCollection.Item property.
By a column index or column heading from the specified row. Use the Row.Item property.
By a row index or row heading from the specified column. Use the Column.Item property.
See the How to: Access a Row or Column example to learn how to get an individual row or column.
- By a cell index or by row and column indexes from the specified range of cells. Use the Range.Item property. See the How to: Access a Range of Cells document to learn how to access an individual range of cells in a worksheet.
using DevExpress.Spreadsheet;
// ...
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cell cellA1 = worksheet[0, 0]; // Cell A1
Cell cellB2 = worksheet.Cells["B2"]; // Cell B2
Cell cellC3 = worksheet.Cells[2, 2]; // Cell C3
Cell cellD4 = worksheet.Rows[3][3]; // Cell D4
Cell cellE5 = worksheet.Rows[4]["E"]; // Cell E5
Cell cellF6 = worksheet.Rows["6"][5]; // Cell F6
Cell cellG7 = worksheet.Columns[6][6]; // Cell G7
Cell cellH8 = worksheet.Columns["H"][7]; // Cell H8
Cell cellI9 = worksheet.Columns["I"]["9"]; // Cell I9
// Access a cell from the range of cells.
Cell cellB5 = worksheet.Range["B3:D8"][6]; // Cell B5
Cell cellD6 = worksheet.Range["B3:D8"][3, 2]; // Cell D6
The following images demonstrate how rows and columns are indexed in a worksheet and in a specified range of cells (the workbook is opened in Microsoft® Excel®).
Row and Column Indexes and Names in Worksheet | Cell, Row and Column Indexes in a Cell Range |
---|---|
See Also