Click or drag to resize

TableStyle Class

Represents a table style.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentStyle
    SautinSoft.Document.TablesTableStyle

Namespace: SautinSoft.Document.Tables
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public sealed class TableStyle : Style

The TableStyle type exposes the following members.

Constructors
 NameDescription
Public methodTableStyle Initializes a new instance of the TableStyle class.
Top
Properties
 NameDescription
Public propertyBaseStyle Gets or sets the style on which this style is based.
Public propertyCellFormat Gets or sets the table cell format.
Public propertyCharacterFormat Gets or sets the character format.
Public propertyConditionalFormats Gets a collection of conditional TableStyleFormats.
Public propertyParagraphFormat Gets or sets the paragraph format.
Public propertyRowFormat Gets or sets the table row format.
Public propertyStyleType Gets the type of the style.
(Overrides StyleStyleType)
Public propertyTableFormat Gets or sets the table format.
Top
Methods
 NameDescription
Public methodEquals Determines whether the specified object is equal to this TableStyle instance.
(Overrides ObjectEquals(Object))
Top
Remarks
Styles provide a way to format your document in a consistent way so when you change your formatting options on a style, all document elements referencing that style will be changed.
Example

See Developer Guide: How to create new styles and apply them to various elements

How to create new styles and apply them to various elements in C#
using SautinSoft.Document;
using SautinSoft.Document.Tables;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            CreateStyles();
        }
        /// <summary>
        /// This sample shows how to create new styles and apply them to various elements.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/styles-create.php
        /// </remarks>
        public static void CreateStyles()
        {
            string documentPath = @"Styles.docx";

            // Let's create document.
            DocumentCore dc = new DocumentCore();

            // Create 3 styles: CharacterStyle, ParagraphStyle and TableStyle

            // 1. Create CharacterStyle
            CharacterStyle charStyle = new CharacterStyle("Green");
            charStyle.CharacterFormat = new CharacterFormat()
            {
                FontName = "Calibri",
                Size = 20,
                FontColor = Color.Green,
                UnderlineStyle = UnderlineType.Single
            };

            // 2. Create ParagraphStyle
            ParagraphStyle parStyle = new ParagraphStyle("Center");
            parStyle.ParagraphFormat.Alignment = HorizontalAlignment.Center;

            // 3. Create TableStyle
            TableStyle tblStyle = new TableStyle("Blue Table");
            tblStyle.CellFormat.BackgroundColor = new Color("#358CCB");            

            // 4. Add the styles to the style collection.
            dc.Styles.Add(charStyle);
            dc.Styles.Add(parStyle);
            dc.Styles.Add(tblStyle);

            // 5. Add some document content and apply the styles.
            // Add a paragraph and text.

            dc.Sections.Add(
            new Section(dc,
                new Paragraph(dc,
                new Run(dc, "Once upon a time, in a far away swamp, there lived an ogre named "),
                new Run(dc, "Shrek") { CharacterFormat = { Style = charStyle } },
                new Run(dc, " whose precious solitude is suddenly shattered by an invasion of annoying fairy tale characters..."))
                { ParagraphFormat = { Style = parStyle } }));

            // Add a table (1 x 2).
            Table tbl = new Table(dc, 1, 2);
            tbl.TableFormat.Style = tblStyle;
            tbl.Rows[0].Cells[0].Content.Start.Insert("Column 1");
            tbl.Rows[0].Cells[1].Content.Start.Insert("Column 2");
            dc.Sections[0].Blocks.Add(tbl);

            // Save our document into DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to create new styles and apply them to various elements in VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Tables

Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
            CreateStyles()
        End Sub
        ''' Get your free 30-day key here:   
        ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' This sample shows how to create new styles and apply them to various elements.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/styles-create.php
        ''' </remarks>
        Public Shared Sub CreateStyles()
            Dim documentPath As String = "Styles.docx"

            ' Let's create document.
            Dim dc As New DocumentCore()

            ' Create 3 styles: CharacterStyle, ParagraphStyle and TableStyle

            ' 1. Create CharacterStyle
            Dim charStyle As New CharacterStyle("Green")
            charStyle.CharacterFormat = New CharacterFormat() With {
                .FontName = "Calibri",
                .Size = 20,
                .FontColor = Color.Green,
                .UnderlineStyle = UnderlineType.Single
            }

            ' 2. Create ParagraphStyle
            Dim parStyle As New ParagraphStyle("Center")
            parStyle.ParagraphFormat.Alignment = HorizontalAlignment.Center

            ' 3. Create TableStyle
            Dim tblStyle As New TableStyle("Blue Table")
            tblStyle.CellFormat.BackgroundColor = New Color("#358CCB")

            ' 4. Add the styles to the style collection.
            dc.Styles.Add(charStyle)
            dc.Styles.Add(parStyle)
            dc.Styles.Add(tblStyle)

            ' 5. Add some document content and apply the styles.
            ' Add a paragraph and text
            dc.Sections.Add(New Section(dc))
            Dim p As New Paragraph(dc)
            p.ParagraphFormat.Style = parStyle
            dc.Sections(0).Blocks.Add(p)

            p.Inlines.Add(New Run(dc, "Once upon a time, in a far away swamp, there lived an ogre named "))
            Dim r As New Run(dc, "Shrek")
            r.CharacterFormat.Style = charStyle
            p.Inlines.Add(r)
            p.Inlines.Add(New Run(dc, " whose precious solitude is suddenly shattered by an invasion of annoying fairy tale characters..."))

            ' Add a table (1 x 2).
            Dim tbl As New Table(dc, 1, 2)
            tbl.TableFormat.Style = tblStyle
            tbl.Rows(0).Cells(0).Content.Start.Insert("Column 1")
            tbl.Rows(0).Cells(1).Content.Start.Insert("Column 2")
            dc.Sections(0).Blocks.Add(tbl)

            ' Save our document into DOCX format.
            dc.Save(documentPath)

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also