Click or drag to resize

Table Class

Represents a table in a document.
Inheritance Hierarchy

Namespace:  SautinSoft.Document.Tables
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.14 (3.8.6.14)
Syntax
public sealed class Table : Block, 
	IContentElement

The Table type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyColumns
Gets the table columns.
Public propertyContent
Gets the ContentRange of the current element.
(Inherited from Element.)
Public propertyDocument
Gets the owner document.
(Inherited from Element.)
Public propertyElementType
Gets the ElementType of this element instance.
(Overrides ElementElementType.)
Public propertyMetadata
Gets the metadata (non-visual properties) of this Table instance.
Public propertyNextSibling
Gets the next Element sibling.
(Inherited from Element.)
Public propertyParent
Gets the parent of this element instance.
(Inherited from Element.)
Public propertyParentCollection
Gets the BlockCollection that contains this Block instance.
(Inherited from Block.)
Public propertyPositioning
Gets the floating table positioning settings.
Public propertyPreviuosSibling
Gets the previous Element sibling.
(Inherited from Element.)
Public propertyCode exampleRows
Gets the table rows.
Public propertyCode exampleTableFormat
Gets or sets the table format.
Top
Methods
  NameDescription
Public methodClone
Clones this element instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleGetChildElements(Boolean)
Gets the child elements.
(Inherited from Element.)
Public methodCode exampleGetChildElements(Boolean, ElementType)
Gets the child elements filtered by ElementType.
(Inherited from Element.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Explicit Interface Implementations
Examples
Add a Table into a document using C#
using SautinSoft.Document;
using SautinSoft.Document.Tables;

namespace Example
{
    class Program
    {
        private static DocumentCore dc;

        static void Main(string[] args)
        {
            CreateTable();
        }

        /// <summary>
        /// Creates a new cell within a table and fills the it in staggered order.
        /// </summary>
        /// <param name="rowIndex">Row index.</param>
        /// <param name="colIndex">Column index.</param>
        /// <returns>New table cell.</returns>
        static TableCell NewCell(int rowIndex, int colIndex)
        {
            TableCell cell = new TableCell(dc);

            cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Black, 1);

            if (colIndex % 2 == 1 && rowIndex % 2 == 0 || colIndex % 2 == 0 && rowIndex % 2 == 1)
            {
                cell.CellFormat.BackgroundColor = Color.Black;
            }

            Run run = new Run(dc, string.Format("Row - {0}; Col - {1}", rowIndex, colIndex));
            run.CharacterFormat.FontColor = Color.Auto;

            cell.Blocks.Content.Replace(run.Content);

            return cell;
        }             

        /// <summary>
        /// Creates a new document with a table.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/tables.php
        /// </remarks>
        static void CreateTable()
        {
            dc = new DocumentCore();           

            string filePath = @"Result-file.docx";

            Table table = new Table(dc, 5, 5, NewCell);

            // Place the 'Table' at the start of the 'Document'.
            // By the way, we didn't create a 'Section' in our document.
            // As we're using 'Content' property, a 'Section' will be created automatically if necessary.
            dc.Content.Start.Insert(table.Content);
            dc.Save(filePath);

            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
Add a Table into a document using VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Tables

Namespace Example
    Friend Class Program
        Private Shared dc As DocumentCore

        Shared Sub Main(ByVal args() As String)
            CreateTable()
        End Sub

        ''' <summary>
        ''' Creates a new cell within a table and fills the it in staggered order.
        ''' </summary>
        ''' <param name="rowIndex">Row index.</param>
        ''' <param name="colIndex">Column index.</param>
        ''' <returns>New table cell.</returns>
        Public Shared Function NewCell(ByVal rowIndex As Integer, ByVal colIndex As Integer) As TableCell
            Dim cell As New TableCell(dc)

            cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Black, 1)

            If colIndex Mod 2 = 1 AndAlso rowIndex Mod 2 = 0 OrElse colIndex Mod 2 = 0 AndAlso rowIndex Mod 2 = 1 Then
                cell.CellFormat.BackgroundColor = Color.Black
            End If

            Dim run As New Run(dc, String.Format("Row - {0}; Col - {1}", rowIndex, colIndex))
            run.CharacterFormat.FontColor = Color.Auto

            cell.Blocks.Content.Replace(run.Content)

            Return cell
        End Function

        ''' <summary>
        ''' Creates a new document with a table.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/examples/tables.php
        ''' </remarks>
        Public Shared Sub CreateTable()
            dc = New DocumentCore()

            Dim filePath As String = "Result-file.docx"

            Dim table As New Table(dc, 5, 5, AddressOf NewCell)

            ' Place the 'Table' at the start of the 'Document'.
            ' By the way, we didn't create a 'Section' in our document.
            ' As we're using 'Content' property, a 'Section' will be created automatically if necessary.
            dc.Content.Start.Insert(table.Content)
            dc.Save(filePath)

            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also