Back to Devexpress

Table.ShowHeaders Property

officefileapi-devexpress-dot-spreadsheet-dot-table-22b7b87d.md

latest9.6 KB
Original Source

Table.ShowHeaders Property

Gets or sets whether the table header row is visible.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
bool ShowHeaders { get; set; }
vb
Property ShowHeaders As Boolean

Property Value

TypeDescription
Boolean

true , to display the header row at the top of the table; otherwise, false.

|

Remarks

Use the ShowHeaders property to show or hide the table header row that contains the names of table columns. The table header row is highlighted in the following image.

To get the cell range that contains the whole header row of the table, use the Table.HeaderRowRange property. To change the names of individual columns, use the TableColumn.Name property.

The appearance of a table header row is specified by the corresponding element of the table style applied to the table (the table style element of the TableStyleElementType.HeaderRow type).

Example

To format a table by applying a table style, assign the corresponding TableStyle object to the Table.Style property. Access the required table style object from the IWorkbook.TableStyles collection by the table style name. Built-in table styles can also be obtained by their ids (the BuiltInTableStyleId enumeration members).

A table style consists of the collection of table style elements (TableStyle.TableStyleElements). Each table style element (TableStyleElement) specifies the formatting for a particular element of a table. The TableStyleElementType enumerator lists supported table style element types. The Table object provides the following properties to optionally specify table elements to be formatted as defined by the corresponding elements of the applied table style.

PropertyDescription
Table.ShowHeadersDisplays the header row in the table and formats it as specified by the TableStyleElementType.HeaderRow element of the applied table style.
Table.ShowTotalsDisplay the total row in the table and formats it as specified by the TableStyleElementType.TotalRow element of the applied table style.
Table.ShowTableStyleRowStripesApplies striped row formatting to a table as specified by the TableStyleElementType.FirstRowStripe and TableStyleElementType.SecondRowStripe elements of the applied table style.
Table.ShowTableStyleColumnStripesapplies striped column formatting to a table as specified by the TableStyleElementType.FirstColumnStripe and TableStyleElementType.SecondColumnStripe elements of the applied table style.
Table.ShowTableStyleFirstColumnFormats the first column of the table as specified by the TableStyleElementType.FirstColumn, TableStyleElementType.FirstHeaderCell and TableStyleElementType.FirstTotalCell elements of the applied table style.
Table.ShowTableStyleLastColumnFormats the last column of the table as specified by the TableStyleElementType.LastColumn, TableStyleElementType.LastHeaderCell and TableStyleElementType.LastTotalCell elements of the applied table style.

This example demonstrates how to access a table style by its name and apply it to an existing table. The Table.ShowHeaders and Table.ShowTotals properties are set to true to show the header and total row of the table.

The Table.ShowTableStyleRowStripes and Table.ShowTableStyleColumnStripes properties are used to apply the striped column formatting to the table.

vb
Private Sub ApplyBuiltInTableStyle(ByVal workbook As IWorkbook, ByVal table As Table, ByVal styleName As String)
    ' Access the workbook's collection of table styles.
    Dim tableStyles As TableStyleCollection = workbook.TableStyles

    ' Access the built-in table style from the collection by its name.
    Dim tableStyle As TableStyle = tableStyles(styleName)

    ' Apply the table style to the existing table.
    table.Style = tableStyle

    ' Show header and total rows.
    table.ShowHeaders = True
    table.ShowTotals = True

    ' Apply banded column formatting to the table.
    table.ShowTableStyleRowStripes = False
    table.ShowTableStyleColumnStripes = True
End Sub
csharp
void ApplyBuiltInTableStyle(IWorkbook workbook, Table table, string styleName) {
    // Access the workbook's collection of table styles.
    TableStyleCollection tableStyles = workbook.TableStyles;

    // Access the built-in table style from the collection by its name.
    TableStyle tableStyle = tableStyles[styleName];

    // Apply the table style to the existing table.
    table.Style = tableStyle;

    // Show header and total rows.
    table.ShowHeaders = true;
    table.ShowTotals = true;

    // Apply banded column formatting to the table.
    table.ShowTableStyleRowStripes = false;
    table.ShowTableStyleColumnStripes = true;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the ShowHeaders property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheet-use-cell-range-as-data-source/CS/RangeDataSource/Form1.cs#L49

csharp
Table sheetDataTable = sheet.Tables[0];
if (sheetDataTable.ShowHeaders)
    options.UseFirstRowAsHeader = true;

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/TableActions.cs#L100

csharp
// Show header and total rows.
table.ShowHeaders = true;
table.ShowTotals = true;

winforms-spreadsheet-use-cell-range-as-data-source/VB/RangeDataSource/Form1.vb#L54

vb
Dim sheetDataTable As Table = sheet.Tables(0)
If sheetDataTable.ShowHeaders Then
    options.UseFirstRowAsHeader = True

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/TableActions.vb#L94

vb
' Show header and total rows.
table.ShowHeaders = True
table.ShowTotals = True

See Also

Spreadsheet Tables

Table Interface

Table Members

DevExpress.Spreadsheet Namespace