officefileapi-devexpress-dot-spreadsheet-dot-worksheet-a501bfa5.md
Provides access to the collection of all cells contained in the worksheet.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
CellCollection Cells { get; }
ReadOnly Property Cells As CellCollection
| Type | Description |
|---|---|
| CellCollection |
A CellCollection object specifying the worksheet’s collection of cells.
|
Use the Cells property to manipulate all worksheet cells simultaneously as a cell range. To access a range including cells that are actually used in the worksheet, use the Worksheet.GetUsedRange method.
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 cell index or by row and column indexes from the specified range of cells. Use the CellRange.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;
// ...
IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets[0];
Cell cellA1 = worksheet[0, 0]; // Cell A1
Cell cellB2 = worksheet.Cells["B2"]; // Cell B2
Cell cellC2 = worksheet.Cells[1, 2]; // Cell C2
Cell cellD3 = worksheet.Cells[2, 3]; // Cell D3
Cell cellE4 = worksheet.Rows[3]["E"]; // Cell E4
Cell cellF4 = worksheet.Rows["4"][5]; // Cell F4
Cell cellG5 = worksheet.Columns[6][4]; // Cell G5
Cell cellH6 = worksheet.Columns["H"][5]; // Cell H6
Cell cellI7 = worksheet.Columns["I"]["7"]; // Cell I7
// Access a cell from the range of cells.
Cell cellB5 = worksheet.Range["B3:D6"][6]; // Cell B5
Cell cellD6 = worksheet.Range["B3:D6"][3, 2]; // Cell D6
Imports DevExpress.Spreadsheet
' ...
Dim workbook As IWorkbook = spreadsheetControl1.Document
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim cellA1 As Cell = worksheet(0, 0) ' Cell A1
Dim cellB2 As Cell = worksheet.Cells("B2") ' Cell B2
Dim cellC2 As Cell = worksheet.Cells(1, 2) ' Cell C2
Dim cellD3 As Cell = worksheet.Cells(2, 3) ' Cell D3
Dim cellE4 As Cell = worksheet.Rows(3)("E") ' Cell E4
Dim cellF4 As Cell = worksheet.Rows("4")(5) ' Cell F4
Dim cellG5 As Cell = worksheet.Columns(6)(4) ' Cell G5
Dim cellH6 As Cell = worksheet.Columns("H")(5) ' Cell H6
Dim cellI7 As Cell = worksheet.Columns("I")("7") ' Cell I7
' Access a cell from the range of cells.
Dim cellB5 As Cell = worksheet.Range("B3:D6")(6) ' Cell B5
Dim cellD6 As Cell = worksheet.Range("B3:D6")(3, 2) ' Cell D6
The following code snippets (auto-collected from DevExpress Examples) contain references to the Cells property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/DataTableActions.cs#L16
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L14"];
wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/DataTableActions.cs#L16
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L14"];
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:D4"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Delete a row that contains the "B2" cell.
worksheet.DeleteCells(worksheet.Cells["B2"], DeleteMode.EntireRow);
#endregion #DeleteRows
// Delete a row that contains the "B2"cell.
worksheet.DeleteCells(worksheet.Cells["B2"], DeleteMode.EntireRow);
#endregion #DeleteRows
winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/DataTableActions.vb#L13
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L14")
wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/DataTableActions.vb#L15
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L14")
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:F6"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Delete a row that contains the "B2" cell.
worksheet.DeleteCells(worksheet.Cells("B2"), DeleteMode.EntireRow)
#End Region ' #DeleteRows
' Delete a row that contains the "B2" cell.
worksheet.DeleteCells(worksheet.Cells("B2"), DeleteMode.EntireRow)
' #End Region ' #DeleteRows
See Also
Cells and Cell Ranges in Spreadsheet Documents