Click or drag to resize

TableCell Class

Represents a single cell in a table row, which contains the table’s content.
Inheritance Hierarchy

Namespace:  SautinSoft.Document.Tables
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.28 (3.8.6.28)
Syntax
public sealed class TableCell : Element, 
	IContentElement

The TableCell type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyBlocks
The collection of Block elements (Paragraphs, Table, etc) inside this cell.
Public propertyCode exampleCellFormat
Gets and sets cell formatting.
Public propertyColumnSpan
The attributes COLSPAN (“how many across”) and ROWSPAN (“how many down”) indicate how many columns or rows a cell should take up.
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 propertyNextSibling
Gets the next Element sibling.
(Inherited from Element.)
Public propertyParent
Public propertyParentCollection
Public propertyPreviuosSibling
Gets the previous Element sibling.
(Inherited from Element.)
Public propertyRowSpan
The attributes COLSPAN (“how many across”) and ROWSPAN (“how many down”) indicate how many columns or rows a cell should take up.
Top
Methods
  NameDescription
Public methodClone
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
How to modify an existing table in C#
using System.IO;
using System.Linq;
using SautinSoft.Document;
using SautinSoft.Document.Tables;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            ModifyTable();
        }

        /// <summary>
        /// How to modify an existing table in a document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/modify-table.php
        /// </remarks>
        public static void ModifyTable()
        {
            string sourcePath = @"..\..\table.docx";
            string destPath = "Table modified.docx";

            // Load a document with a table.
            DocumentCore dc = DocumentCore.Load(sourcePath);

            // Find a first table in the document.
            Table table = (Table)dc.GetChildElements(true, ElementType.Table).First();

            // Set dashed borders and yellow background for all cells.
            for (int r = 0; r < table.Rows.Count; r++)
            {
                for (int c = 0; c < table.Rows[r].Cells.Count; c++)
                {
                    TableCell cell = table.Rows[r].Cells[c];
                    cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Dashed, Color.Black, 1);
                    cell.CellFormat.BackgroundColor = new Color("#FFCC00");
                }
            }

            // Save the document as DOCX.
            dc.Save(destPath, new DocxSaveOptions());

            // Show the source and the dest documents.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(sourcePath) { UseShellExecute = true });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(destPath) { UseShellExecute = true });
        }
    }
}
How to modify an existing table in VB.Net
Imports System
Imports System.IO
Imports System.Linq
Imports SautinSoft.Document
Imports SautinSoft.Document.Tables

Module Sample
    Sub Main()
        ModifyTable()
    End Sub

    ''' <summary>
    ''' How to modify an existing table in a document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/modify-table.php
    ''' </remarks>
    Sub ModifyTable()
        Dim sourcePath As String = "..\table.docx"
        Dim destPath As String = "Table modified.docx"

        ' Load a document with a table.
        Dim dc As DocumentCore = DocumentCore.Load(sourcePath)

        ' Find a first table in the document.
        Dim table As Table = CType(dc.GetChildElements(True, ElementType.Table).First(), Table)

        ' Set dashed borders and yellow background for all cells.
        For r As Integer = 0 To table.Rows.Count - 1
            Dim c As Integer = 0
            Do While c < table.Rows(r).Cells.Count
                Dim cell As TableCell = table.Rows(r).Cells(c)
                cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Dashed, Color.Black, 1)
                cell.CellFormat.BackgroundColor = New Color("#FFCC00")
                c += 1
            Loop
        Next r

        ' Save the document as DOCX.
        dc.Save(destPath, New DocxSaveOptions())

        ' Show the source and the dest documents.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(sourcePath) With {.UseShellExecute = True})
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(destPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also