Table constructor

Initializes a new instance of the Table class.

public Table(DocumentBase doc)
docDocumentBaseThe owner document.


When Table is created, it belongs to the specified document, but is not yet part of the document and ParentNode is null.

To append Table to the document use InsertAfter or InsertBefore on the story where you want the table inserted.


Shows how to create a table.

Document doc = new Document();
Table table = new Table(doc);

// Tables contain rows, which contain cells, which may have paragraphs
// with typical elements such as runs, shapes, and even other tables.
// Calling the "EnsureMinimum" method on a table will ensure that
// the table has at least one row, cell, and paragraph.
Row firstRow = new Row(doc);

Cell firstCell = new Cell(doc);

Paragraph paragraph = new Paragraph(doc);

// Add text to the first cell in the first row of the table.
Run run = new Run(doc, "Hello world!");

doc.Save(ArtifactsDir + "Table.CreateTable.docx");

Shows how to build a nested table without using a document builder.

public void CreateNestedTable()
    Document doc = new Document();

    // Create the outer table with three rows and four columns, and then add it to the document.
    Table outerTable = CreateTable(doc, 3, 4, "Outer Table");

    // Create another table with two rows and two columns and then insert it into the first table's first cell.
    Table innerTable = CreateTable(doc, 2, 2, "Inner Table");

    doc.Save(ArtifactsDir + "Table.CreateNestedTable.docx");

/// <summary>
/// Creates a new table in the document with the given dimensions and text in each cell.
/// </summary>
private static Table CreateTable(Document doc, int rowCount, int cellCount, string cellText)
    Table table = new Table(doc);

    for (int rowId = 1; rowId <= rowCount; rowId++)
        Row row = new Row(doc);

        for (int cellId = 1; cellId <= cellCount; cellId++)
            Cell cell = new Cell(doc);
            cell.AppendChild(new Paragraph(doc));
            cell.FirstParagraph.AppendChild(new Run(doc, cellText));


    // You can use the "Title" and "Description" properties to add a title and description respectively to your table.
    // The table must have at least one row before we can use these properties.
    // These properties are meaningful for ISO / IEC 29500 compliant .docx documents (see the OoxmlCompliance class).
    // If we save the document to pre-ISO/IEC 29500 formats, Microsoft Word ignores these properties.
    table.Title = "Aspose table title";
    table.Description = "Aspose table description";

    return table;

See Also