Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
A table style defines a set of formatting that can be easily applied to a table. Formatting such as borders, shading, alignment, and font can be set in a table style and applied to many tables for a consistent appearance.
Aspose.Words supports applying a table style to a table and also reading properties of any table style. Table styles are preserved during loading and saving in the following ways:
The user can create a new style and add it to style collection. The Add method is used to create a new table style.
The following code example shows how to create a new user defined table style:
If necessary, you can copy a table style that already exists in a certain document into your style collection using the AddCopy method.
It is important to know that with this copying, the linked styles are also copied.
The following code example shows how to import a style from one document to another document:
EXAMPLE
Aspose.Words provides a TableStyle inherited from the Style class. TableStyle facilitates the user to apply different style options like as shading, padding, indentation, CellSpacing and Font, etc.
In addition, Aspose.Words provides the StyleCollection class and a few properties of the Table class to specify which table style we will work with: Style, StyleIdentifier, StyleName, and StyleOptions.
Aspose.Words also provides ConditionalStyle class that represents special formatting applied to some area of a table with an assigned table style, and the ConditionalStyleCollection that represents a collection of ConditionalStyle objects. This collection contains a permanent set of items representing one item for each value of the ConditionalStyleType enumeration type. The ConditionalStyleType enumeration defines all possible table areas to which conditional formatting may be defined in a table style.
In this case, conditional formatting can be defined for all possible table area defined under the ConditionalStyleType enumeration type.
The following code example shows how to define conditional formatting for header row of the table:
You can also choose which table parts to apply styles to, such as first column, last column, banded rows. They are listed in the TableStyleOptions enumeration and are applied through the StyleOptions property. The TableStyleOptions enumeration allows a bitwise combination of these features.
The following code example shows how to create a new table with a table style applied:
The pictures below show a representation of the Table Styles in Microsoft Word and their corresponding properties in Aspose.Words.

Aspose.Words also provides the ExpandTableStylesToDirectFormatting method to take formatting found on a table style and expands it onto the rows and cells of the table as direct formatting. Try combining formatting with table style and cell style.
The following code example shows how to expand the formatting from styles onto table rows and cells as direct formatting:
Q: How do I create a custom table style in C++?
A: Use the StyleCollection::Add method to create a new TableStyle. Set the desired properties (borders, shading, font, etc.) on the style object, then add it to the document’s StyleCollection. The style can later be applied to any Table via its Style property.
Q: Can I copy a table style from another document?
A: Yes. Load the source document, retrieve the required TableStyle, and use StyleCollection::AddCopy on the target document’s StyleCollection. This copies the style together with any linked styles.
Q: How do I apply an existing table style to a table?
A: After creating or loading a Table, set its StyleIdentifier or StyleName property to the name of the desired style, or assign the TableStyle object directly to the table’s Style property.
Q: How can I define conditional formatting (e.g., header row shading) for a table style?
A: Access the ConditionalStyleCollection of the TableStyle and add a ConditionalStyle for the required ConditionalStyleType (e.g., ConditionalStyleType::HeaderRow). Configure the formatting (shading, font, etc.) on that ConditionalStyle.
Q: What if I need the style’s formatting as direct formatting on the table cells?
A: Call Document::ExpandTableStylesToDirectFormatting(). This expands all style‑based formatting into explicit formatting on each row and cell, preserving the appearance while removing the style reference.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.