[C#]
// Load the document.
Document doc = new Document(MyDir + "Table.Document.doc");
// Get the first and second table in the document.// The rows from the second table will be appended to the end of the first table.
Table firstTable = (Table) doc.GetChild(NodeType.Table, 0, true);
Table secondTable = (Table) doc.GetChild(NodeType.Table, 1, true);
// Append all rows from the current table to the next.// Due to the design of tables even tables with different cell count and widths can be joined into one table.while (secondTable.HasChildNodes)
firstTable.Rows.Add(secondTable.FirstRow);
// Remove the empty table container.
secondTable.Remove();
doc.Save(ArtifactsDir + "Table.CombineTables.doc");

Examples

Shows how to build a formatted table that contains 2 rows and 2 columns.

[C#]
Document doc = new Document(MyDir + "Table.Document.doc");
// Here we get all tables from the Document node. You can do this for any other composite node// which can contain block level nodes. For example you can retrieve tables from header or from a cell// containing another table (nested tables).
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
// Iterate through all tables in the documentforeach (Table table in tables.OfType<Table>())
{
// Get the index of the table node as contained in the parent node of the tableint tableIndex = table.ParentNode.ChildNodes.IndexOf(table);
Console.WriteLine("Start of Table {0}", tableIndex);
// Iterate through all rows in the tableforeach (Row row in table.Rows.OfType<Row>())
{
int rowIndex = table.Rows.IndexOf(row);
Console.WriteLine("\tStart of Row {0}", rowIndex);
// Iterate through all cells in the rowforeach (Cell cell in row.Cells.OfType<Cell>())
{
int cellIndex = row.Cells.IndexOf(cell);
// Get the plain text content of this cell.
String cellText = cell.ToString(SaveFormat.Text).Trim();
// Print the content of the cell.
Console.WriteLine("\t\tContents of Cell:{0} = \"{1}\"", cellIndex, cellText);
}
Console.WriteLine("\tEnd of Row {0}", rowIndex);
}
Console.WriteLine("End of Table {0}", tableIndex);
Console.WriteLine();
}

[C#]
Document doc = new Document();
// We start by creating the table object. Note how we must pass the document object// to the constructor of each node. This is because every node we create must belong// to some document.
Table table = new Table(doc);
// Add the table to the document.
doc.FirstSection.Body.AppendChild(table);
// Here we could call EnsureMinimum to create the rows and cells for us. This method is used// to ensure that the specified node is valid, in this case a valid table should have at least one// row and one cell, therefore this method creates them for us.// Instead we will handle creating the row and table ourselves. This would be the best way to do this// if we were creating a table inside an algorithm for example.
Row row = new Row(doc);
row.RowFormat.AllowBreakAcrossPages = true;
table.AppendChild(row);
// We can now apply any auto fit settings.
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
// Create a cell and add it to the row
Cell cell = new Cell(doc);
cell.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue;
cell.CellFormat.Width = 80;
// Add a paragraph to the cell as well as a new run with some text.
cell.AppendChild(new Paragraph(doc));
cell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 1 Text"));
// Add the cell to the row.
row.AppendChild(cell);
// We would then repeat the process for the other cells and rows in the table.// We can also speed things up by cloning existing cells and rows.
row.AppendChild(cell.Clone(false));
row.LastCell.AppendChild(new Paragraph(doc));
row.LastCell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 2 Text"));
// Remove spacing between cells
table.AllowCellSpacing = false;
doc.Save(ArtifactsDir + "Table.InsertTableUsingNodes.doc");