Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

Worksheet.GetUsedRange() Method

Returns the used range on the specified worksheet.

Namespace: DevExpress.Spreadsheet

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

Declaration

Range GetUsedRange()

Returns

Type Description
Range

A Range 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 Range.Value, Range.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.
Range usedRange = worksheet.GetUsedRange();
// Restrict the worksheet's visible area to the used range.
spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, usedRange.ColumnCount, usedRange.RowCount);

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetUsedRange() method.

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.

See Also