Skip to main content

TableStyle Interface

A table style.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.1.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

[ComVisible(true)]
public interface TableStyle :
    TablePropertiesBase,
    TableCellPropertiesBase,
    CharacterPropertiesBase,
    ParagraphPropertiesBase

Remarks

To create a new style, use the TableStyleCollection.CreateNew method. Call the TableStyleCollection.Add method and pass the TableStyle object as the method parameter to add a newly created style to the collection. Otherwise, you cannot apply the table style.

To apply a style to a table, use the Table.Style property. Note that each paragraph in a cell may have its own style.

The Document.DefaultTableProperties property allows you to specify default format options for the table.

Example

The code sample below creates a new table style and applies it to a table:

result

View Example

using DevExpress.Office.Utils;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;

static void CreateAndApplyTableStyle(RichEditDocumentServer wordProcessor)
{
    // Access a document.
    Document document = wordProcessor.Document;

    // Start to edit the document.
    document.BeginUpdate();

    // Create a new table style.
    TableStyle tStyleMain = document.TableStyles.CreateNew();

    // Specify table style options.
    tStyleMain.AllCaps = true;
    tStyleMain.FontName = "Segoe Condensed";
    tStyleMain.FontSize = 14;
    tStyleMain.Alignment = ParagraphAlignment.Center;

    TableBorders tableBorders = tStyleMain.TableBorders;
    tableBorders.InsideHorizontalBorder.LineStyle =
         TableBorderLineStyle.Dotted;

    tableBorders.InsideVerticalBorder.LineStyle =
         TableBorderLineStyle.Dotted;

    tableBorders.Top.LineThickness = 1.5f;
    tableBorders.Top.LineStyle = TableBorderLineStyle.Double;
    tableBorders.Left.LineThickness = 1.5f;
    tableBorders.Left.LineStyle = TableBorderLineStyle.Double;
    tableBorders.Bottom.LineThickness = 1.5f;
    tableBorders.Bottom.LineStyle = TableBorderLineStyle.Double;
    tableBorders.Right.LineThickness = 1.5f;
    tableBorders.Right.LineStyle = TableBorderLineStyle.Double;

    tStyleMain.CellBackgroundColor = Color.LightBlue;
    tStyleMain.TableLayout = TableLayoutType.Fixed;
    tStyleMain.Name = "MyTableStyle";

    // Add the style to the collection of styles.
    document.TableStyles.Add(tStyleMain);

    // Finalize to edit the document.
    document.EndUpdate();

    // Start to edit the document.
    document.BeginUpdate();

    // Create a table with three rows and columns
    // at the document range's start position.
    Table table = document.Tables.Create(document.Range.Start, 3, 3);

    // Set the table width to a fixed value.
    table.TableLayout = TableLayoutType.Fixed;
    table.PreferredWidthType = WidthType.Fixed;
    table.PreferredWidth = Units.InchesToDocumentsF(3.5f);

    // Set the cell width to a fixed value. 
    table[1, 1].PreferredWidthType = WidthType.Fixed;
    table[1, 1].PreferredWidth = Units.InchesToDocumentsF(1.5f);

    // Apply the created style to the table.
    table.Style = tStyleMain;

    // Finalize to edit the document.
    document.EndUpdate();

    // Insert text to the table cell.
    document.InsertText(table[1, 1].Range.Start, "STYLED");

}
See Also