The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

Worksheet.GetUsedRange() Method

Returns the used range on the specified worksheet.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

CellRange GetUsedRange()
Function GetUsedRange As CellRange
CellRange GetUsedRange()
Function GetUsedRange As CellRange
CellRange GetUsedRange()
Function GetUsedRange As CellRange

Returns

Type Description
CellRange

A CellRange object that is the range of modified cells.

Returns

Type Description
CellRange

A CellRange object that is the range of modified cells.

Returns

Type Description
CellRange

A CellRange object that is the range of modified cells.

Remarks

In the Spreadsheet document model, empty cells in a worksheet do not exist until they are accessed in some way or modified. The GetUsedRange method returns a worksheet range that complies with the requirements listed below.

  1. The used range is a continuous range of non-empty cells. The top-left cell of the used range is a cell located at the intersection of the topmost row and the leftmost column containing non-empty cells. The bottom-right cell of the used range is a cell located at the intersection of the lowest row and the rightmost column containing non-empty cells.

    Note

    The cell is not empty if it contains a CellRange.Value, CellRange.Formula, or has any Formatting properties which are not null.

    Spreadsheet_GetUsedRange_B2E6

  2. The used range is extended to include the leftmost and rightmost empty columns containing visual formatting (fill or border). However, the returned range cannot include more than 8192 columns. Hidden columns that contain no data or formatting options applied, as well as empty columns with a custom width are not included in the used range.

    Spreadsheet_GetUsedRange_A2H6

  3. The used range is extended to include the topmost and bottommost empty rows containing visual formatting (fill or border).

    Spreadsheet_GetUsedRange_B1E9

  4. The used range includes all the tables regardless their visibility state (a table occupies a range determined by the Table.Range property).

    Spreadsheet_GetUsedRange_Tables

  5. Pictures are not included in the used range.

    Spreadsheet_GetUsedRange_Pictures

  6. Merged cells are included in the used range, even if they are located in hidden columns or rows.

    Spreadsheet_GetUsedRange_MergedCells

  7. Conditional formatting is ignored.

The following example shows how to use the GetUsedRange method to restrict the number of visible rows and columns in a worksheet:

// Access the active worksheet.
Worksheet worksheet = spreadsheetControl.ActiveWorksheet;
// Get the range containing non-empty cells.
CellRange usedRange = worksheet.GetUsedRange();
// Restrict the worksheet's visible area to the used range.
spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, usedRange.ColumnCount, usedRange.RowCount);
See Also