TableStyle class

Represents a table style.

To learn more, visit the Working with Tables documentation article.

public class TableStyle : Style


Aliases { get; }Gets all aliases of this style. If style has no aliases then empty array of string is returned.
Alignment { get; set; }Specifies the alignment for the table style.
AllowBreakAcrossPages { get; set; }Gets or sets a flag indicating whether text in a table row is allowed to split across a page break.
AutomaticallyUpdate { get; set; }Specifies whether this style is automatically redefined based on the appropriate value.
BaseStyleName { get; set; }Gets/sets the name of the style this style is based on.
Bidi { get; set; }Gets or sets whether this is a style for a right-to-left table.
Borders { get; }Gets the collection of default cell borders for the style.
BottomPadding { get; set; }Gets or sets the amount of space (in points) to add below the contents of table cells.
BuiltIn { get; }True if this style is one of the built-in styles in MS Word.
CellSpacing { get; set; }Gets or sets the amount of space (in points) between the cells.
ColumnStripe { get; set; }Gets or sets a number of columns to include in the banding when the style specifies odd/even columns banding.
ConditionalStyles { get; }Collection of conditional styles that may be defined for this table style.
Document { get; }Gets the owner document.
Font { get; }Gets the character formatting of the style.
IsHeading { get; }True when the style is one of the built-in Heading styles.
IsQuickStyle { get; set; }Specifies whether this style is shown in the Quick Style gallery inside MS Word UI.
LeftIndent { get; set; }Gets or sets the value that represents the left indent of a table.
LeftPadding { get; set; }Gets or sets the amount of space (in points) to add to the left of the contents of table cells.
LinkedStyleName { get; set; }Gets/sets the name of the Style linked to this one. Returns empty string if no styles are linked.
List { get; }Gets the list that defines formatting of this list style.
ListFormat { get; }Provides access to the list formatting properties of a paragraph style.
Locked { get; set; }Specifies whether this style is locked.
Name { get; set; }Gets or sets the name of the style.
NextParagraphStyleName { get; set; }Gets/sets the name of the style to be applied automatically to a new paragraph inserted after a paragraph formatted with the specified style.
ParagraphFormat { get; }Gets the paragraph formatting of the style.
Priority { get; set; }Gets/sets the integer value that represents the priority for sorting the styles in the Styles task pane.
RightPadding { get; set; }Gets or sets the amount of space (in points) to add to the right of the contents of table cells.
RowStripe { get; set; }Gets or sets a number of rows to include in the banding when the style specifies odd/even row banding.
SemiHidden { get; set; }Gets/sets whether the style hides from the Styles gallery and from the Styles task pane.
Shading { get; }Gets a Shading object that refers to the shading formatting for table cells.
StyleIdentifier { get; }Gets the locale independent style identifier for a built-in style.
Styles { get; }Gets the collection of styles this style belongs to.
TopPadding { get; set; }Gets or sets the amount of space (in points) to add above the contents of table cells.
Type { get; }Gets the style type (paragraph or character).
UnhideWhenUsed { get; set; }Gets/sets whether the style used in the current document unhides from the Styles gallery and from the Styles task pane. True when the used style should be shown in the Styles gallery.
VerticalAlignment { get; set; }Specifies the vertical alignment for the cells.


Equals(Style)Compares with the specified style. Styles Istds are compared for built-in styles only. Styles defaults are not included in comparison. Base style, linked style and next paragraph style are recursively compared.
Remove()Removes the specified style from the document.


Shows how to create custom style settings for the table.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();

TableStyle tableStyle = (TableStyle)doc.Styles.Add(StyleType.Table, "MyTableStyle1");
tableStyle.AllowBreakAcrossPages = true;
tableStyle.Bidi = true;
tableStyle.CellSpacing = 5;
tableStyle.BottomPadding = 20;
tableStyle.LeftPadding = 5;
tableStyle.RightPadding = 10;
tableStyle.TopPadding = 20;
tableStyle.Shading.BackgroundPatternColor = Color.AntiqueWhite;
tableStyle.Borders.Color = Color.Blue;
tableStyle.Borders.LineStyle = LineStyle.DotDash;
tableStyle.VerticalAlignment = CellVerticalAlignment.Center;

table.Style = tableStyle;

// Setting the style properties of a table may affect the properties of the table itself.
Assert.AreEqual(5.0d, table.CellSpacing);
Assert.AreEqual("MyTableStyle1", table.StyleName);

doc.Save(ArtifactsDir + "Table.TableStyleCreation.docx");

See Also