Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / Headers / Creating a Span in a Header
In This Topic
    Creating a Span in a Header
    In This Topic

    You can create cell spans in a header, for example, to make a header for multiple columns or rows, or both, as shown in the figure below.

    Spread with multiple column header rows

    You can create cell spans in either the column headers or row headers or both. For more background about creating cell spans, refer to Creating a Span of Cells.

    Use these methods when creating a span in a header:

    You can specify how the header spans are selected with the CellSpanSelectionPolicy property.

    For information on creating multiple rows in the column headers or multiple columns in the row headers, refer to Creating a Header with Multiple Rows or Columns.

    You can customize the labels in these headers. For instructions for customizing the labels, see Setting the Header Text.

    Using a Shortcut

    Call the Sheets object AddColumnHeaderSpanCell or AddRowHeaderSpanCell method.

    Example

    This example code sets the first cell in the column header to span across two columns.

    C#
    Copy Code
    // Set the number of rows in the column header.
    fpSpread1.ActiveSheet.ColumnHeader.RowCount = 3;
    // Set the number of columns in the row header.
    fpSpread1.ActiveSheet.RowHeader.ColumnCount = 2;
    // Define the labels for the spanned column header cells.
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 0].Text = "East";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 1].Text = "West";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 2].Text = "East";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 3].Text = "West";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 4].Text = "East";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 5].Text = "West";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 6].Text = "East";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[2, 7].Text = "West";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[1, 0].Text = "1st Quarter";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[1, 2].Text = "2nd Quarter";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[1, 4].Text = "3rd Quarter";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[1, 6].Text = "4th Quarter";
    fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 0].Text = "Fiscal Year 2004";
    // Define the column header cell spans.
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 0, 1, 2);
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 2, 1, 2);
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 4, 1, 2);
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 6, 1, 2);
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 0, 1, 8);
    // Define the label for the spanned row header cells.
    fpSpread1.ActiveSheet.RowHeader.Cells[0,0].Text ="Branch #";
    // Define the row header cell span.
    fpSpread1.ActiveSheet.AddRowHeaderSpanCell(0, 0, 12, 1);
    
    VB
    Copy Code
    ' Set the number of rows in the column header.
    fpSpread1.ActiveSheet.ColumnHeader.RowCount = 3
    ' Set the number of columns in the row header.
    fpSpread1.ActiveSheet.RowHeader.ColumnCount = 2
    ' Define the labels for the spanned column header cells.
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 0).Text = "East"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 1).Text = "West"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 2).Text = "East"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 3).Text = "West"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 4).Text = "East"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 5).Text = "West"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 6).Text = "East"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(2, 7).Text = "West"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(1, 0).Text = "1st Quarter"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(1, 2).Text = "2nd Quarter"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(1, 4).Text = "3rd Quarter"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(1, 6).Text = "4th Quarter"
    fpSpread1.ActiveSheet.ColumnHeader.Cells(0, 0).Text = "Fiscal Year 2004"
    ' Define the column header cell spans.
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 0, 1, 2)
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 2, 1, 2)
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 4, 1, 2)
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(1, 6, 1, 2)
    fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 0, 1, 8)
    ' Define the label for the spanned row header cells.
    fpSpread1.ActiveSheet.RowHeader.Cells(0,0).Text ="Branch #"
    ' Define the row header cell span.
    fpSpread1.ActiveSheet.AddRowHeaderSpanCell(0, 0, 12, 1)
    

    Using the Spread Designer

    1. Select the sheet tab for the sheet for which you want to span header cells.
    2. Select the row or column for which you want to set custom header text, then right-click and choose Headers.
    3. In the Header Editor, click the left-most header cell in the set of cells for which you want to create a span.
    4. In the property list for that header cell, set the ColumnSpan or RowSpan property to the number of cells to span starting from the selected header cell.
    5. Click OK to close the Header Editor.
    6. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
    See Also