Headers are located at the top of each printed page or in the top section of a worksheet. You can perform various operations on both row and column headers, such as hiding them, adding multiple headers, customizing their appearance, and more.
The following sections explain various operations on headers that you can perform in Spread for WPF.
You can add multiple rows to column headers or multiple columns to row headers to create multi-level headers. You can display letters, numbers, or custom text in these headers. When a user clicks a header, the corresponding row or column is selected by default. To add multiple headers, use the RowCount and ColumnCount properties of the IColumnHeader and IRowHeader interfaces.
Refer to the following example code to add multiple headers as shown in the above image.
You can modify the default height of a specific row in a column header. To accomplish this, first access the worksheet's column header using the ColumnHeader property, use the Cells property to reference a specific cell of ColumnHeader, and then set its RowHeight property. Note that the row height value is set in pixels.
Refer to the following example code to set the height of the first row of column headers.
You can modify the default width of a specific column in a row header. To accomplish this, first access the worksheet's row header using the RowHeader property, use the Cells property to reference a specific cell of RowHeader, and then set its ColumnWidth property. Note that the column width value is set in pixels.
Refer to the following example code to set the column width of the row header.
By default the spreadSheet component displays letters in the column headers and numbers in the row headers. You can customize the appearance of row and column headers using different properties of IRange interface, such as cell type, text orientation, background color, text alignments, etc.
Refer to the following example code to customize headers using the CellType, Orientation, Interior, and HorizontalAlignment properties of the IRange interface.
Limitations
You can merge row and column header cells to span multiple rows or columns and add labels to the header cells using the Text property of the IRange interface. To merge headers with its default selection behavior, use the Merge method of the IRange interface.
By default, clicking on a header cell selects the entire column. However, you can customize the selection behavior for a merged header cell with the MergedCellSelectionPolicy enumeration.
The following images illustrate the properties of the MergedCellSelectionPolicy enumeration and the selection range when the user clicks the cell in the second row and first column of the column header ("Quarter 1" cell).
Default | Contained |
Select only the column (row) from which the join originates. |
Select a cell that fits within the header area. |
Ignore | Intersected |
Selects only the column (row) that is clicked. |
Select all the cells in the header area. |
Refer to the following example code that demonstrates cell spanning in a row header with two columns and a column header with three rows.
By default, both column and row headers are visible in a worksheet. However, you can hide either or both by disabling the Visible property of the IColumnHeader and IRowHeader interfaces.
The following image shows a worksheet where both column and row headers are not visible.
The following example code hides column and row headers as shown in the above image.