.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Worksheet.GetUsedRange() Method

Returns the used range on the specified worksheet.

Namespace: DevExpress.Spreadsheet

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


CellRange GetUsedRange()


Type Description

A CellRange object that is the range of modified cells.


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.


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


  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.


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


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


  5. Drawing objects(pictures,shapes and charts) are not included in the used range.


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


  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);

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


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