officefileapi-devexpress-dot-spreadsheet-dot-cellrange-8c412b38.md
Gets the number of columns in the cell range.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
int ColumnCount { get; }
ReadOnly Property ColumnCount As Integer
| Type | Description |
|---|---|
| Int32 |
An integer that specifies the number of columns.
|
To obtain the number of rows in the cell range, use the CellRange.RowCount property.
If the current cell range is a complex (union) range, the ColumnCount property returns the number of columns in the rectangular cell range that covers all areas of the union range. For example, the ColumnCount value for the union range B3:C4, D6:E7 shown in the image below is 4.
The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnCount 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.
how-to-export-cell-range-to-a-datatable/CS/ExportToDataTableExample/Form1.cs#L40
if (firstDataRowIndex < rowCount) {
for (int col = 0; col < range.ColumnCount; col++) {
CellValueType cellType = range[firstDataRowIndex, col].Value.Type;
how-to-use-excel-add-ins-in-winforms-spreadsheet/CS/SpreadsheetAddIn/Form1.cs#L165
int height = parameter.RowCount;
int width = parameter.ColumnCount;
object[,] result = (object[,])Array.CreateInstance(typeof(object), new[] { height, width }, new[] { 1, 1 });
winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/CellActions.cs#L205
// Get the number of cells in the range.
int cellCount = sourceRange.RowCount * sourceRange.ColumnCount;
// Get the number of cells in the range.
int cellCount = sourceRange.RowCount * sourceRange.ColumnCount;
how-to-export-cell-range-to-a-datatable/VB/ExportToDataTableExample/Form1.vb#L39
If firstDataRowIndex < rowCount Then
For col As Integer = 0 To range.ColumnCount - 1
Dim cellType As CellValueType = range(firstDataRowIndex, col).Value.Type
how-to-use-excel-add-ins-in-winforms-spreadsheet/VB/SpreadsheetAddIn/Form1.vb#L178
Dim height As Integer = parameter.RowCount
Dim width As Integer = parameter.ColumnCount
Dim result(,) As Object = CType(Array.CreateInstance(GetType(Object), {height, width}, {1, 1}), Object(,))
winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/CellActions.vb#L191
' Get the number of cells in the range.
Dim cellCount As Integer = sourceRange.RowCount * sourceRange.ColumnCount
' Get the number of cells in the range.
Dim cellCount As Integer = sourceRange.RowCount * sourceRange.ColumnCount
See Also