Search Results for

    Show / Hide Table of Contents

    Class Table

    Represents a table element within the document.

    Inheritance
    System.Object
    ContentElement
    ParentElement
    TableElement
    Table
    Implements
    System.Collections.Generic.IEnumerable<TableCell>
    System.Collections.IEnumerable
    System.Collections.Generic.IEnumerable<TableRow>
    IronSoftware.Abstractions.Word.ITable
    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IParent<IronSoftware.Abstractions.Word.IWordDocumentObjectCollection, IronSoftware.Abstractions.Word.IWordDocumentObject>
    Inherited Members
    TableElement.ExtractImages()
    TableElement.ExtractShapes()
    TableElement.Borders
    TableElement.BackgroundColor
    ParentElement.AddChild(IWordDocumentObject[])
    ParentElement.InsertChildToIndex(Int32, IWordDocumentObject[])
    ParentElement.Remove()
    ParentElement.RemoveChildren(IWordDocumentObject[])
    ParentElement.RemoveAllChildren()
    ParentElement.ExtractElements<T>()
    ParentElement.GetChildByIndex<T>(Int32)
    ParentElement.Clone()
    ParentElement.CloneObject()
    ParentElement.LogObjectTree()
    ParentElement.Texts
    ParentElement.Tables
    ParentElement.Children
    ContentElement.Replace(IWordDocumentObject)
    ContentElement.GetIndex<T>()
    ContentElement.Parent
    ContentElement.Status
    Namespace: IronWord.Models
    Assembly: IronWord.dll
    Syntax
    public class Table : TableElement

    Table is the grid object you build whenever a Word document needs structured rows and columns, such as an invoice, a report, or a data summary. One instance holds the rows, cells, and styling for a single table, and it is the type a developer reaches for behind a search like "C# Word table". Build it with dimensions and drop it into a document in a couple of lines.

    A table is created either empty (new Table()), from rows (new Table(params TableRow[])), or sized up front with new Table(int row, int column), which is the usual starting point. Once built, attach it to a document with WordDocument.AddTable or pass it to the WordDocument(Table) constructor. The cells are reachable through zero-based indexing: table[row, column] returns a TableCell, and table[row] returns a TableRow, so you assign or read content positionally.

    Populate cells by assigning a TableCell (for example table[0, 0] = new TableCell(new TextContent("Number"))) or by calling GetCell and adding content to it. Rows and columns grow with AddRow, AddColumn, RemoveRow, and RemoveColumn, and MergeCells joins a rectangular range. Styling lives on the table's own properties: Zebra takes a ZebraColor for alternating row shading, Borders takes a TableBorders, Shading sets the fill, Style applies a TableStyle, and Width, Justification, and the cell-margin properties such as TopCellMargin control layout. The Columns and Rows lists expose the structure for iteration.

    using IronWord;
    using IronWord.Models;
    
    Table table = new Table(3, 3);
    table.Zebra = new ZebraColor("FFFFFF", "DDDDDD");
    table[0, 0] = new TableCell(new TextContent("Number"));
    
    WordDocument doc = new WordDocument(table);
    doc.SaveAs("Document.docx");

    The add a table how-to walks through dimensions, styling, and cell content, the add table example shows a populated grid saved to DOCX, and the document element tutorial covers how tables sit in the document model.

    Constructors

    Table()

    Initializes a new instance of the Table class.

    Declaration
    public Table()

    Table(TableRow[])

    Initializes a new instance of the Table class with the specified rows.

    Declaration
    public Table(params TableRow[] rows)
    Parameters
    Type Name Description
    TableRow[] rows

    The table rows to be added.

    Table(Int32, Int32)

    Initializes a new instance of the Table class with the specified number of rows and columns.

    Declaration
    public Table(int row, int column)
    Parameters
    Type Name Description
    System.Int32 row

    The number of rows in the table.

    System.Int32 column

    The number of columns in each row of the table.

    Properties

    BottomCellMargin

    Gets or sets the margin between the bottom cell border and the cell contents.

    Declaration
    public Nullable<uint> BottomCellMargin { get; }
    Property Value
    Type Description
    System.Nullable<System.UInt32>
    Remarks

    Stored in twips by default.

    Columns

    Gets the list of TableColumn elements contained within this table. Thread-safe implementation with double-checked locking for performance.

    Declaration
    public List<TableColumn> Columns { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<TableColumn>

    Data

    Raw data

    Declaration
    public DataTable Data { get; }
    Property Value
    Type Description
    System.Data.DataTable

    Direction

    Gets or sets the text direction of the table.

    Declaration
    public Direction Direction { get; set; }
    Property Value
    Type Description
    Direction

    Index

    Gets the index of this table within the parent's list of children.

    Declaration
    public int Index { get; set; }
    Property Value
    Type Description
    System.Int32

    Item[Int32]

    Gets or sets the TableRow at the specified row index.

    Declaration
    public TableRow this[int row] { get; set; }
    Parameters
    Type Name Description
    System.Int32 row

    The index of the row.

    Property Value
    Type Description
    TableRow

    The TableRow at the specified row index.

    Exceptions
    Type Condition
    System.IndexOutOfRangeException

    Thrown when the specified row index is out of range.

    Item[Int32, Int32]

    Gets or sets the TableCell at the specified row and column indices.

    Declaration
    public TableCell this[int row, int column] { get; set; }
    Parameters
    Type Name Description
    System.Int32 row

    The index of the row.

    System.Int32 column

    The index of the column.

    Property Value
    Type Description
    TableCell

    The TableCell at the specified row and column indices.

    Exceptions
    Type Condition
    System.IndexOutOfRangeException

    Thrown when the specified row or column index is out of range.

    Justification

    Gets or sets the justification of the text within the table.

    Declaration
    public Nullable<JustificationValues> Justification { get; }
    Property Value
    Type Description
    System.Nullable<IronSoftware.Abstractions.Word.JustificationValues>

    LeftCellMargin

    Gets or sets the margin between the left cell border and the cell contents.

    Declaration
    public Nullable<uint> LeftCellMargin { get; }
    Property Value
    Type Description
    System.Nullable<System.UInt32>
    Remarks

    Stored in twips by default.

    MergedCells

    Gets a list of cell merges applied to the table.

    Declaration
    public List<MergeCell> MergedCells { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.List<MergeCell>

    RightCellMargin

    Gets or sets the margin between the right cell border and the cell contents.

    Declaration
    public Nullable<uint> RightCellMargin { get; }
    Property Value
    Type Description
    System.Nullable<System.UInt32>
    Remarks

    Stored in twips by default.

    Rows

    Gets the list of TableRow elements contained within this table. Thread-safe implementation with caching for performance.

    Declaration
    public List<ITableRow> Rows { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<IronSoftware.Abstractions.Word.ITableRow>

    Shading

    Gets or sets the Sets the color of the shading and fill of the table.

    Declaration
    public Shading Shading { get; set; }
    Property Value
    Type Description
    Shading

    Style

    Gets or sets the default styling of the table.

    Declaration
    public TableStyle Style { get; set; }
    Property Value
    Type Description
    TableStyle
    Remarks

    Any of these styling properties can be overridden by the styling of the table's rows and cells.

    TopCellMargin

    Gets or sets the margin between the top cell border and the cell contents.

    Declaration
    public Nullable<uint> TopCellMargin { get; }
    Property Value
    Type Description
    System.Nullable<System.UInt32>
    Remarks

    Stored in twips by default.

    Width

    Gets or sets the width of the table.

    Declaration
    public Nullable<long> Width { get; set; }
    Property Value
    Type Description
    System.Nullable<System.Int64>
    Remarks

    Value is in twips by default.

    Zebra

    Gets or sets the pair of colors used for applying zebra background to table rows.

    Declaration
    public ZebraColor Zebra { get; set; }
    Property Value
    Type Description
    ZebraColor

    Methods

    AddColumn()

    Adds a new column to the table.

    Declaration
    public Table AddColumn()
    Returns
    Type Description
    Table

    AddRow(TableRow)

    Initializes a new instance of the Table class with the specified row.

    Declaration
    public Table AddRow(TableRow row)
    Parameters
    Type Name Description
    TableRow row

    The table row to be added.

    Returns
    Type Description
    Table

    GetCell(Int32, Int32)

    Gets the TableCell at the specified row and column indices.

    Declaration
    public TableCell GetCell(int row, int column)
    Parameters
    Type Name Description
    System.Int32 row

    The index of the row containing the desired TableCell.

    System.Int32 column

    The index of the column containing the desired TableCell.

    Returns
    Type Description
    TableCell

    The TableCell at the specified row and column indices.

    GetCellValue(Int32, Int32)

    Gets the contents of a specific cell within the table.

    Declaration
    public List<IWordDocumentObject> GetCellValue(int rowIndex, int columnIndex)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index of the cell.

    System.Int32 columnIndex

    The column index of the cell.

    Returns
    Type Description
    System.Collections.Generic.List<IronSoftware.Abstractions.Word.IWordDocumentObject>

    A list of ContentElement objects representing the cell's content.

    GetEnumerator()

    Provides an enumerator that iterates through all TableCell elements in the table, traversing rows and cells.

    Declaration
    public IEnumerator<TableCell> GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<TableCell>

    An enumerator for the table cells.

    GetRow(Int32)

    Gets the TableRow at the specified row indices.

    Declaration
    public TableRow GetRow(int row)
    Parameters
    Type Name Description
    System.Int32 row

    The index of the row in this table.

    Returns
    Type Description
    TableRow

    The TableCell at the specified row and column indices.

    GetWidth(MeasurementUnit)

    Gets the width of the Table in the specified measurement unit.

    Declaration
    public double GetWidth(MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    MeasurementUnit measurementUnit

    The measurement unit for the width. Default is twentieths of a point (Twips).

    Returns
    Type Description
    System.Double

    The width of the Table in the specified measurement unit.

    MergeCells(Int32, Int32, Int32, Int32)

    Merges a range of cells within the table.

    Declaration
    public Table MergeCells(int startRow, int startColumn, int endRow, int endColumn)
    Parameters
    Type Name Description
    System.Int32 startRow

    The starting row index of the merged area (inclusive).

    System.Int32 startColumn

    The starting column index of the merged area (inclusive).

    System.Int32 endRow

    The ending row index of the merged area (inclusive).

    System.Int32 endColumn

    The ending column index of the merged area (inclusive).

    Returns
    Type Description
    Table

    RemoveColumn(Int32)

    Removes a column from the table.

    Declaration
    public Table RemoveColumn(int index)
    Parameters
    Type Name Description
    System.Int32 index

    The index of the column to be removed.

    Returns
    Type Description
    Table

    RemoveRow(Int32)

    Removes a row from the table.

    Declaration
    public Table RemoveRow(int index)
    Parameters
    Type Name Description
    System.Int32 index

    The index of the row to be removed.

    Returns
    Type Description
    Table

    SetCellValue(Int32, Int32, ContentElement)

    Sets the content of a specific cell within the table.

    Declaration
    public Table SetCellValue(int row, int column, ContentElement content)
    Parameters
    Type Name Description
    System.Int32 row

    The row index of the cell.

    System.Int32 column

    The column index of the cell.

    ContentElement content

    The ContentElement object representing the new content for the cell.

    Returns
    Type Description
    Table

    SetWidth(Double, MeasurementUnit)

    Sets the width of the table.

    Declaration
    public Table SetWidth(double width, MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    System.Double width

    The width value to set.

    MeasurementUnit measurementUnit

    The measurement unit of the provided height. Default is twentieths of a point (Twips).

    Returns
    Type Description
    Table

    Split(Int32, Int32, Int32, Int32)

    Splits a cell in the table into multiple rows and columns.

    Declaration
    public Table Split(int row, int column, int toRow, int toColumn)
    Parameters
    Type Name Description
    System.Int32 row

    The index of the starting row to split.

    System.Int32 column

    The index of the starting column to split.

    System.Int32 toRow

    The number of the row for the split.

    System.Int32 toColumn

    The number of columns for the split.

    Returns
    Type Description
    Table

    Implements

    System.Collections.Generic.IEnumerable<>
    System.Collections.IEnumerable
    System.Collections.Generic.IEnumerable<>
    IronSoftware.Abstractions.Word.ITable
    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IParent<, >

    Inherited members

    ExtractImages()
    ExtractShapes()
    Borders
    BackgroundColor
    AddChild(IWordDocumentObject[])
    InsertChildToIndex(Int32, IWordDocumentObject[])
    Remove()
    RemoveChildren(IWordDocumentObject[])
    RemoveAllChildren()
    ExtractElements<T>()
    GetChildByIndex<T>(Int32)
    Clone()
    CloneObject()
    LogObjectTree()
    Texts
    Tables
    Children
    Replace(IWordDocumentObject)
    GetIndex<T>()
    Parent
    Status
    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet
    %s requires a valid license key for further deployment. Get Trial Below.
    ironsuite
    Blue key in circleGet Started for Free
    30 days full access • No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet Started for Free
    The trial form was submitted successfully.
    Grey check in circleTrial key delivered
    Your key has been issued and sent to your email.
    Calendar in circleBook Free Live Demo
    No cards • no pitches • no commitments Pick a time for a quick, personalized demo
    Get the most out of your 30-day trial with:

    Live product and key features walk-through

    Project-specific recommendations

    All your questions answered

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation

    Want to deploy Iron Suite
    to a live project for FREE?

    What’s included?

    • Test in production without watermarks
    • 30 days fully functional product
    • 24/5 technical support during trial
    ironpdf Logo
    ironword Logo
    ironxl Logo
    ironppt Logo
    ironocr Logo
    ironbarcode Logo
    ironqr Logo
    ironprint Logo
    ironzip Logo
    ironwebscraper Logo
    Iron Software sales team
    Online 24/5
    Have Enterprise licensing requirements?
    Request Iron Suite Enterprise trial
    Key in blue circle

    Get your free 30-day Trial Key instantly

    Your trial license will be sent to your email address

    No limitations. 100% unlocked. No credit card.

    bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
    Or
    Key in blue circle

    Complete Your Trial Key Signup

    Tell us a little more about yourself.

    Key in blue circleNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
    Key in blue circle

    Your license key has been delivered to your inbox

    Can't find it? Check your spam folder.

    What’s next?
    Install with NuGet
    Add IronWord to your project
    Quickstart Guide
    Helpful resources to get started

    Need help getting started?

    Book a Free Live Demo

    See IronWord in action and get your licensing questions answered, or

    Key in blue circle

    Your demo request is in.

    You'll receive an invite via email shortly.

    What’s next?
    Explore Documentation
    Review Licensing Options
    badge_greencheck_in_yellowcircle
    Thank you
    Your trial key should be in the email.
    If it is not, please contact support@ironsoftware.com
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronWord
    Your trial key should be in the email.
    If it is not, please contact support@ironsoftware.com