Rows and Columns
- 7 minutes to read
Cells in a worksheet are organized into 1,048,576 rows (Worksheet.Rows) and 16,384 columns (Worksheet.Columns). Each row is numbered (1, 2, 3, …) and each column is lettered (A, B, C, …) if the A1 reference style is used, or numbered (1, 2, 3, …) if the R1C1 reference style is specified. Row and column headers are displayed at the left and at the top of a worksheet, respectively. You can hide or show these headers using the SpreadsheetViewOptions.ShowColumnHeaders, SpreadsheetViewOptions.ShowRowHeaders or WorksheetView.ShowHeadings property. To enable end-users to change the visibility of row and column headers, provide the Show Ribbon page group for the SpreadsheetControl. For an example on how to provide a Ribbon UI for the SpreadsheetControl, see the Getting Started topic.
By default, the SpreadsheetControl displays all columns and rows, but you can specify the number of columns and rows available for display and edit via the WorksheetDisplayArea.SetSize method. This method allows you to restrict the number of visible columns and rows for the specified worksheet. Refer to the How to: Restrict the Number of Visible Rows and Columns in a Worksheet example for details.
The SpreadsheetControl also allows you to customize the appearance of row and column headers. For example, you can specify the height of column headers and width of row headers using the SpreadsheetViewOptions.ColumnHeaderHeight and SpreadsheetViewOptions.RowHeaderWidth property, respectively. You can also perform custom painting of headers by handling the SpreadsheetControl.CustomDrawRowHeader, SpreadsheetControl.CustomDrawRowHeaderBackground, SpreadsheetControl.CustomDrawColumnHeader and SpreadsheetControl.CustomDrawColumnHeaderBackground events. Use the properties provided by the CustomDrawObjectEventsArgs base class to paint text, graphic primitives or images. The image below shows a document with custom row and column headers.
End-User Capabilities
To enable end-users to modify rows and columns in a worksheet, add a set of Ribbon pages to the SpreadsheetControl.
The table below lists the basic row and column operations available to end-users via Ribbon pages (or the spreadsheet context menu) and the corresponding API methods and properties.
- Insert a row
- Insert a column
- Delete rows and columns
- Hide a column
- Hide a row
- Unhide rows and columns
- Freeze rows and columns
- Unfreeze rows and columns
- Set column width
- Set row height
Action | End-user capabilities | API methods/properties |
---|---|---|
Insert a row |
| |
Insert a column |
| |
Delete rows and columns |
| |
Hide a column |
| |
Hide a row |
| |
Unhide columns and rows |
| |
Freeze rows and columns | On the View tab, in the Window group, click the Freeze Panes button to display the drop-down list. Select one of the following.
A black border appears beneath the frozen row(s) and to the right of the frozen column(s). | |
Unfreeze rows and columns | On the View tab, in the Window group, click the Freeze Panes button and select the Unfreeze Panes item. | |
Set column width |
| Worksheet.DefaultColumnWidthInCharacters |
Set row height |
|
End-User Restrictions
The SpreadsheetControl allows you to prevent end-users from modifying rows and columns in a worksheet. For example, it may be necessary to restrict end-users from showing or deleting columns or rows that contain formulas. To implement end-user restrictions, use the SpreadsheetControlOptions.Behavior property, which provides access to the restriction settings. The table below lists possible restrictions you can set when working with columns and rows in the SpreadsheetControl.
Restriction | Description |
---|---|
SpreadsheetRowBehaviorOptions.AutoFit | Gets or sets whether or not end-users are allowed to use the AutoFit feature for rows. |
SpreadsheetRowBehaviorOptions.Delete | Gets or sets whether or not end-users are allowed to delete rows. |
SpreadsheetRowBehaviorOptions.Hide | Gets or sets whether or not end-users are allowed to hide rows. |
SpreadsheetRowBehaviorOptions.Insert | Gets or sets whether or not end-users are allowed to insert rows. |
SpreadsheetRowBehaviorOptions.Resize | Gets or sets whether or not end-users are allowed to resize rows. |
SpreadsheetRowBehaviorOptions.Unhide | Gets or sets whether or not end-users are allowed to unhide rows. |
SpreadsheetColumnBehaviorOptions.AutoFit | Gets or sets whether or not end-users are allowed to use the AutoFit feature for columns. |
SpreadsheetColumnBehaviorOptions.Delete | Gets or sets whether or not end-users are allowed to delete columns. |
SpreadsheetColumnBehaviorOptions.Hide | Gets or sets whether or not end-users are allowed to hide columns. |
SpreadsheetColumnBehaviorOptions.Insert | Gets or sets whether or not end-users are allowed to insert columns. |
SpreadsheetColumnBehaviorOptions.Resize | Gets or sets whether or not end-users are allowed to resize columns. |
SpreadsheetColumnBehaviorOptions.Unhide | Gets or sets whether or not end-users are allowed to unhide columns. |
SpreadsheetBehaviorOptions.FreezePanes | Gets or sets whether or not end-users are allowed to freeze panes. |
Set the desired property to the DocumentCapability.Disabled or DocumentCapability.Hidden value, to disable or hide the corresponding command in the Ribbon UI and the spreadsheet popup menu. You can also prevent the context menu from being displayed, as described in the How to: Customize or Hide the Popup Menu example.