# Headers

A topic showing how to work with headers in Spread for WPF, including text, size, color, merge, hide, and many more.

## Content

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.

## Add Multiple Headers

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](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IColumnHeader.RowCount.html) and [ColumnCount](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRowHeader.ColumnCount.html) properties of the **IColumnHeader** and **IRowHeader** interfaces.
![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/multiheader.png)
Refer to the following example code to add multiple headers as shown in the above image.
**C#**

```csharp
// Add three rows to the column headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 3;
// Add three columns to the row headers.
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 3;
```

**VB**

```vbnet
' Add three rows to the column headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 3
' Add three columns to the row headers.
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 3
```

## Set Column Header Height

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](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorksheet.ColumnHeader.html) property, use the [Cells](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IColumnHeader.Cells.html) property to reference a specific cell of ColumnHeader, and then set its [RowHeight](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.RowHeight.html) property. Note that the row height value is set in pixels.
![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/setcolumnheadersize.png)
Refer to the following example code to set the height of the first row of column headers.
**C#**

```csharp
// Set the row height of the column header.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1"].RowHeight = 54;
```

**VB**

```vbnet
' Set the row height of the column header.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1").RowHeight = 54
```

## Set Row Header Width

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](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IWorksheet.RowHeader.html) property, use the [Cells](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRowHeader.Cells.html) property to reference a specific cell of RowHeader, and then set its [ColumnWidth](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.ColumnWidth.html) property. Note that the column width value is set in pixels.
![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/setrowheadersize.png)
Refer to the following example code to set the column width of the row header.
**C#**

```csharp
// Set column width of the row header.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells[0,0].ColumnWidth  = 190;
```

**VB**

```vbnet
' Set column width of the row header.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells(0, 0).ColumnWidth = 190
```

## Set Corner Header

The area at the top left of the control where the row header and column header intersect is the corner header. To set the number of rows and columns of the corner header, change the number of rows in the column header and the number of columns in the row header. The row height of the corner header corresponds to the row height of the column header, and the column width corresponds to the column width of the row header.
The following code sets the corner header by setting the [RowCount](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IColumnHeader.RowCount.html) property of the [IColumnHeader](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IColumnHeader.html) and the [ColumnCount](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRowHeader.ColumnCount.html) property of the [IRowHeader](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRowHeader.html) to 5.

```csharp
GcSpreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 5; 
GcSpreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 5; 
```

```vbnet
GcSpreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 5
GcSpreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 5
```

When the user clicks a column header, the corresponding column is selected; when the row header is clicked, the corresponding row is selected; and when the corner header is clicked, the entire control is selected.

## Customize Header Style

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.
![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/customizeheader.png)
Refer to the following example code to customize headers using the [CellType](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.CellType.html), [Orientation](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.Orientation.html), [Interior](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.Interior.html), and [HorizontalAlignment](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.HorizontalAlignment.html) properties of the **IRange** interface.
**C#**

```csharp
// Customize headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1:B1"].CellType = UniversalCellType.FromWorkbook(spreadSheet1.Workbook);
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1:B1"].Orientation = 25;
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1:B1"].Interior.Pattern = GrapeCity.Spreadsheet.PatternType.LinearGradient;
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1:B1"].HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.Center;
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1"].RowHeight = 44;
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1"].Text = "Column1";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["B1"].Text = "Column2";
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 2;
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells[0, 1].Text = "Row1";
```

**VB**

```vbnet
' Customize headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1:B1").CellType = UniversalCellType.FromWorkbook(spreadSheet1.Workbook)
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1:B1").Orientation = 25
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1:B1").Interior.Pattern = GrapeCity.Spreadsheet.PatternType.LinearGradient
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1:B1").HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.Center
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1").RowHeight = 44
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1").Text = "Column1"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("B1").Text = "Column2"
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 2
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells(0, 1).Text = "Row1"
```

**Limitations**

* You cannot set borders for row and column headers.
* You cannot customize automatically merged cells.

## Merge Header Cells

You can merge row and column header cells to span multiple rows or columns and add labels to the header cells using the [Text](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.Text.html) property of the **IRange** interface. To merge headers with its default selection behavior, use the [Merge](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRange.Merge.html) 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](/spreadnet/api/latest/online-wpf/GrapeCity.Wpf.SpreadSheet/GrapeCity.Wpf.SpreadSheet.MergedCellSelectionPolicy.html) 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** | **Ignore** | **Intersected** |
| ------- | --------- | ------ | ----------- |
| ![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/default%20merged%20header.png) <br>Select only the column (row) from which the join originates.<br>This is the default value. | ![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/contained%20merged%20header.png) <br>Select a cell that fits within the header area. | ![image](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/image.14a044.png)<br>Selects only the column (row) that is clicked. | ![image](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/image.f61cc5.png)<br>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.
**C#**

```csharp
spreadSheet1.Workbook.ActiveSheet.RowCount = 20;
spreadSheet1.Workbook.ActiveSheet.ColumnCount = 8;
spreadSheet1.MergedCellSelectionPolicy = MergedCellSelectionPolicy.Default;
// Merge the ColumnHeader cells.
// Set the number of rows in the column headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 3;
// Set the number of columns in the row headers.
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 2;
// Define labels for the merged column header cells.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A3"].Text = "East";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["B3"].Text = "West";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["C3"].Text = "East";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["D3"].Text = "West";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["E3"].Text = "East";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["F3"].Text = "West";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["G3"].Text = "East";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["H3"].Text = "West";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A2"].Text = "Quarter 1";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["C2"].Text = "Quarter 2";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["E2"].Text = "Quarter 3";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["G2"].Text = "Quarter 4";
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1"].Text = "Annual Report";
// Define the merge for the column header cells.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A1:H1"].Merge();
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["A2:B2"].Merge();
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["C2:D2"].Merge();
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["E2:F2"].Merge();
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells["G2:H2"].Merge();
// Merge the RowHeader cells.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells["A1"].Text = "Row 1";
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells["A2"].Text = "Row 2";
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells["A1:B1"].Merge();
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells["A2:B2"].Merge();
```

**VB**

```vbnet
spreadSheet1.Workbook.ActiveSheet.RowCount = 20
spreadSheet1.Workbook.ActiveSheet.ColumnCount = 8
spreadSheet1.MergedCellSelectionPolicy = MergedCellSelectionPolicy.[Default]
' Merge the ColumnHeader cells.
' Set the number of rows in the column headers.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.RowCount = 3
' Set the number of columns in the row headers.
spreadSheet1.Workbook.ActiveSheet.RowHeader.ColumnCount = 2
' Define labels for the merged column header cells.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A3").Text = "East"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("B3").Text = "West"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("C3").Text = "East"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("D3").Text = "West"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("E3").Text = "East"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("F3").Text = "West"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("G3").Text = "East"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("H3").Text = "West"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A2").Text = "Quarter 1"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("C2").Text = "Quarter 2"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("E2").Text = "Quarter 3"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("G2").Text = "Quarter 4"
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1").Text = "Annual Report"
' Define the merge for the column header cells.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A1:H1").Merge()
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("A2:B2").Merge()
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("C2:D2").Merge()
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("E2:F2").Merge()
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Cells("G2:H2").Merge()
' Merge the RowHeader cells.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells("A1").Text = "Row 1"
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells("A2").Text = "Row 2"
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells("A1:B1").Merge()
spreadSheet1.Workbook.ActiveSheet.RowHeader.Cells("A2:B2").Merge()
```

## Hide Headers

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](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IColumnHeader.Visible.html) and [IRowHeader](/spreadnet/api/latest/online-wpf/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.IRowHeader.Visible.html) interfaces.
The following image shows a worksheet where both column and row headers are not visible.
![](https://cdn.mescius.io/document-site-files/images/0f63724f-fddf-4351-8c24-0b4338c0fda9/images/hideheader.png)
The following example code hides column and row headers as shown in the above image.
**C#**

```csharp
// Hide the column header.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Visible = false;
// Hide the row header.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Visible = false;
```

**VB**

```vbnet
' Hide the column header.
spreadSheet1.Workbook.ActiveSheet.ColumnHeader.Visible = False
' Hide the row header.
spreadSheet1.Workbook.ActiveSheet.RowHeader.Visible = False
```