Skip to main content

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.

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

SpreadsheetControl_WorksheetDisplayArea

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

Change the SpreadsheetControl’s Background Color

Use the SpreadsheetViewOptions.BackColor property to change the color of the SpreadsheetControl’s non-editable area.

SpreadsheetControl_WorksheetDisplayArea_Custom_BackColor

spreadsheetControl.Options.View.BackColor = Color.FromArgb(0xef, 0xf6, 0xf3);