Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

TableStyleElements.Item[TableStyleElementType] Property

Gets a table style element by its type.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

TableStyleElement this[TableStyleElementType index] { get; }

Parameters

Name Type Description
index TableStyleElementType

A TableStyleElementType enumeration member.

Property Value

Type Description
TableStyleElement

A TableStyleElement object that is a table style element of the specified type.

Remarks

A table style (TableStyle) consists of the collection of table style elements (TableStyle.TableStyleElements). Each table style element (TableStyleElement) specifies formatting for a particular element of a table. Use the Item property to access and modify individual table style elements.

A TableStyleElement object provides properties to customize the borders (TableStyleElement.Borders), fill (TableStyleElement.Fill) and font (TableStyleElement.Font) for the corresponding table element. If you want to create a style providing striped row or column formating for a table, customize the FirstRowStripe, SecondRowStripe, FirstColumnStripe or SecondColumnStripe table style elements and set their TableStyleElement.StripeSize property, which specifies the banding rule.

Example

This example demonstrates how to create a custom style to format tables.

  1. Add a new table style to the IWorkbook.TableStyles collection by calling the TableStyleCollection.Add method with the table style name passed as a parameter. This method returns the TableStyle object that represents the newly created table style. This object’s TableStyle.Name property is set to the specified name. Other settings are identical to the None table style (the default built-in table style that specifies no formatting for a table).

    Note

    Note that table styles have unique names in the collection. To ensure that there is no table style under the specified name in the collection, use the TableStyleCollection.Contains method.

  2. Modify elements of the created table style (TableStyle.TableStyleElements) within the TableStyle.BeginUpdate and TableStyle.EndUpdate paired methods.
' Access a table.
Dim table As Table = worksheet.Tables(0)

Dim styleName As String = "testTableStyle"

' If the style under the specified name already exists in the collection,
If workbook.TableStyles.Contains(styleName) Then
    ' apply this style to the table.
    table.Style = workbook.TableStyles(styleName)
Else
    ' Add a new table style under the "testTableStyle" name to the TableStyles collection.

    Dim customTableStyle_Renamed As TableStyle = workbook.TableStyles.Add("testTableStyle")

    ' Modify the required formatting characteristics of the table style. 
    ' Specify the format for different table elements.
    customTableStyle_Renamed.BeginUpdate()
    Try
        customTableStyle_Renamed.TableStyleElements(TableStyleElementType.WholeTable).Font.Color = Color.FromArgb(107, 107, 107)

        ' Specify formatting characteristics for the table header row. 
        Dim headerRowStyle As TableStyleElement = customTableStyle_Renamed.TableStyleElements(TableStyleElementType.HeaderRow)
        headerRowStyle.Fill.BackgroundColor = Color.FromArgb(64, 66, 166)
        headerRowStyle.Font.Color = Color.White
        headerRowStyle.Font.Bold = True

        ' Specify formatting characteristics for the table total row. 
        Dim totalRowStyle As TableStyleElement = customTableStyle_Renamed.TableStyleElements(TableStyleElementType.TotalRow)
        totalRowStyle.Fill.BackgroundColor = Color.FromArgb(115, 193, 211)
        totalRowStyle.Font.Color = Color.White
        totalRowStyle.Font.Bold = True

        ' Specify banded row formatting for the table.
        Dim secondRowStripeStyle As TableStyleElement = customTableStyle_Renamed.TableStyleElements(TableStyleElementType.SecondRowStripe)
        secondRowStripeStyle.Fill.BackgroundColor = Color.FromArgb(234, 234, 234)
        secondRowStripeStyle.StripeSize = 1
    Finally
        customTableStyle_Renamed.EndUpdate()
    End Try
    ' Apply the created custom style to the table.
    table.Style = customTableStyle_Renamed
End If
See Also