To create multi-row column headers in ReoGrid, you can use the ExtensionColumnHeader property of the worksheet. This allows you to extend the column header area vertically to accommodate multiple rows of headers, up to a maximum of 10 rows. The cells within these header rows can be merged horizontally or vertically, and you can freely customize the header text and style. Mutiple Cell Header

Creating Multi-Row Headers

Access the Extension Column Header: First, get a reference to the extension column header from your worksheet.

var extensionHeader = worksheet.ExtensionColumnHeader;

Set the Number of Rows: Define the number of rows for the column headers using the RowCount property or the SetRowCount method.

extensionHeader.SetRowCount(3); // Sets the header to have 3 rows

The result is shown in the following figure. Mutiple Cell Header

Access Cells

Cells in multi-row headers, like cells in a worksheet, have their origin coordinates (0,0) at the top-left corner. Mutiple Cell Header

Merging Cells

To merge cells in multi-row headers, use the MergeCells method. Specify the rows and columns to combine as parameters.

extensionHeader.MergeCells(int startRow, int startColumn, int rowSpan, int columnSpan)

Create the code as shown below.

// Merge first cell (0, 0)
extensionHeader.MergeCells(0, 0, 3, 1);

// Merge from cell in row 0, 2nd column (0, 1)
extensionHeader.MergeCells(0, 1, 1, 4);

Mutiple Cell Header

Set Cell Text

extensionHeader[0, 0].Text = "No.";
extensionHeader[0, 1].Text = "ε€§εˆ†ι‘ž";

Mutiple Cell Header

Repeat the MergeCells and Text settings to create a multi-row header.

extensionHeader.MergeCells(0, 0, 3, 1);

extensionHeader.MergeCells(0, 1, 1, 4);
extensionHeader.MergeCells(1, 1, 1, 2);
extensionHeader.MergeCells(1, 3, 1, 2);

extensionHeader.MergeCells(0, 5, 3, 1);

extensionHeader.MergeCells(0, 6, 1, 4);
extensionHeader.MergeCells(1, 6, 2, 1);
extensionHeader.MergeCells(1, 8, 2, 2);

extensionHeader[0, 0].Text = "No.";
extensionHeader[0, 1].Text = "ε€§εˆ†ι‘ž";
extensionHeader[1, 1].Text = "δΈ­εˆ†ι‘ž";
extensionHeader[1, 3].Text = "δΈ­εˆ†ι‘ž";

extensionHeader[0, 6].Text = "ε€§εˆ†ι‘ž";
extensionHeader[2, 1].Text = "ε°εˆ†ι‘ž";
extensionHeader[2, 2].Text = "ε°εˆ†ι‘ž";
extensionHeader[2, 3].Text = "ε°εˆ†ι‘ž";
extensionHeader[2, 4].Text = "ε°εˆ†ι‘ž";

extensionHeader[0, 5].Text = "対豑";

The result is as follows. Mutiple Cell Header

Unmerging Cells

You can unmerge cells using the UnmergeCells method.

extensionHeader.UnmergeCells(0, 7);

Adjust the row height

extensionHeader.Rows[0].Height = 30;

About Column and Cell Selection

Multi-row column headers always allow individual columns to be selected, regardless of whether cells are merged horizontally. Selected columns are displayed in a highlighted color. Multiple Cell Header

If some columns of merged cells are selected, those cells will be displayed in a highlighted color. Multiple Cell Header

About displaying/hiding columns

If a column is set to hidden, a thick line appears in place of the hidden column. Multiple Cell Header for multiple lines

Use with worksheet freeze

Multi-row column headers can be used with worksheet freeze just like regular column headers. When the worksheet is scrolled, some columns will be hidden as shown below. Multiple Cell Header

Use with outlines

Multi-row column headers can be used with outlines just like regular column headers. If columns are collapsed, the corresponding header cells will be hidden. Multiple Cell Header

Was this article helpful?