Click or drag to resize

TableCellFormat Class

Represents a set of properties which shall be applied to a specific TableCell.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentFormat
    SautinSoft.Document.TablesTableCellFormat

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

The TableCellFormat type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleTableCellFormat Initializes a new instance of TableCellFormat class.
Top
Properties
 NameDescription
Public propertyCode exampleBackgroundColor Gets or sets the table cell background color.
Public propertyCode exampleBorders Gets the table cell borders.
Public propertyFitText When true, fits text in the cell, compressing each paragraph to the width of the table cell.
Public propertyCode examplePadding Gets or sets the table cell padding.
Public propertyCode examplePreferredWidth Gets or sets the preferred width of the table cell.
Public propertyTextDirection Gets or sets the direction of the text flow for table cell.
Public propertyCode exampleVerticalAlignment Gets or sets the vertical alignment of text in the table cell.
Public propertyWrapText When true, wrap text for the table cell.
Top
Methods
 NameDescription
Public methodClearFormatting Clears the formatting.
(Overrides FormatClearFormatting)
Public methodClone Clones this TableCellFormat instance.
Public methodEquals Determines whether the specified object is equal to this TableCellFormat instance.
(Overrides ObjectEquals(Object))
Top
Example

See Developer Guide: How apply formatting for table cells

How apply formatting for table cells in C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using SautinSoft.Document.Tables;
using System.Linq;

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

            TableCellFormatting();
        }
        /// <summary>
        /// How apply formatting for table cells.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/tablecell-format.php
        /// </remarks>
        static void TableCellFormatting()
        {
            string filePath = @"TableCellFormatting.docx";

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

            // Add new table.
            Table table = new Table(dc);
            double width = LengthUnitConverter.Convert(100, LengthUnit.Millimeter, LengthUnit.Point);
            table.TableFormat.PreferredWidth = new TableWidth(width, TableWidthUnit.Point);
            table.TableFormat.Borders.SetBorders(MultipleBorderTypes.Inside | MultipleBorderTypes.Outside, 
                BorderStyle.Single, Color.Black, 1);
            dc.Sections.Add(new Section(dc, table));

            TableRow row = new TableRow(dc);
            row.RowFormat.Height = new TableRowHeight(50, HeightRule.Exact);
            table.Rows.Add(row);

            // Create a cells with formatting: borders, background color, vertical alignment and text direction.
            TableCell cell = new TableCell(dc, new Paragraph(dc, "Cell 1"));
            cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Blue, 1);
            cell.CellFormat.BackgroundColor = Color.Yellow;
            row.Cells.Add(cell);

            row.Cells.Add(new TableCell(dc, new Paragraph(dc, "Cell 2"))
            {
                CellFormat = new TableCellFormat()
                {
                    VerticalAlignment = VerticalAlignment.Center
                }
            });

            row.Cells.Add(new TableCell(dc, new Paragraph(dc, "Cell 3"))
            {
                CellFormat = new TableCellFormat()
                {
                    TextDirection = TextDirection.BottomToTop
                }
            });

            // Save our document.
            dc.Save(filePath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
How apply formatting for table cells in VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Imports SautinSoft.Document.Tables
Imports System.Linq

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            TableCellFormatting()
        End Sub
        ''' Get your free 30-day key here:   
        ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' How apply formatting for table cells.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/tablecell-format.php
        ''' </remarks>
        Private Shared Sub TableCellFormatting()
            Dim filePath As String = "TableCellFormatting.docx"

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

            ' Add new table.
            Dim table As New Table(dc)
            Dim width As Double = LengthUnitConverter.Convert(100, LengthUnit.Millimeter, LengthUnit.Point)
            table.TableFormat.PreferredWidth = New TableWidth(width, TableWidthUnit.Point)
            table.TableFormat.Borders.SetBorders(MultipleBorderTypes.Inside Or MultipleBorderTypes.Outside, BorderStyle.Single, Color.Black, 1)
            dc.Sections.Add(New Section(dc, table))

            Dim row As New TableRow(dc)
            row.RowFormat.Height = New TableRowHeight(50, HeightRule.Exact)
            table.Rows.Add(row)

            ' Create a cells with formatting: borders, background color, vertical alignment and text direction.
            Dim cell As New TableCell(dc, New Paragraph(dc, "Cell 1"))
            cell.CellFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Blue, 1)
            cell.CellFormat.BackgroundColor = Color.Yellow
            row.Cells.Add(cell)

            row.Cells.Add(New TableCell(dc, New Paragraph(dc, "Cell 2")) With {
                .CellFormat = New TableCellFormat() With {.VerticalAlignment = VerticalAlignment.Center}
            })

            row.Cells.Add(New TableCell(dc, New Paragraph(dc, "Cell 3")) With {
                .CellFormat = New TableCellFormat() With {.TextDirection = TextDirection.BottomToTop}
            })

            ' Save our document.
            dc.Save(filePath)

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