Skip to main content
A newer version of this page is available. .

How to: Restrict the Number of Visible Rows and Columns in a Worksheet

This example demonstrates how to use the WorksheetDisplayArea.SetSize method to restrict the number of rows and columns the SpreadsheetControl displays in a worksheet.

In particular, the code snippet below shows how to set the active worksheet’s visible area to the used range the Worksheet.GetUsedRange method returns.

// 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 image shows the result:

WPFSpreadsheet_WorksheetDisplayArea