public void SplitTable()
{
//ExStart
//ExId:SplitTableAtRow
//ExSummary:Shows how to split a table into two tables a specific row.
// Load the document.
Document doc = new Document(MyDir + "Table.SimpleTable.doc");
// Get the first table in the document.
Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
// We will split the table at the third row (inclusive).
Row row = firstTable.Rows[2];
// Create a new container for the split table.
Table table = (Table)firstTable.Clone(false);
// Insert the container after the original.
firstTable.ParentNode.InsertAfter(table, firstTable);
// Add a buffer paragraph to ensure the tables stay apart.
firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);
Row currentRow;
do
{
currentRow = firstTable.LastRow;
table.PrependChild(currentRow);
}
while (currentRow != row);
doc.Save(MyDir + @"\Artifacts\Table.SplitTable.doc");
//ExEnd
doc = new Document(MyDir + @"\Artifacts\Table.SplitTable.doc");
// Test we are adding the rows in the correct order and the
// selected row was also moved.
Assert.AreEqual(row, table.FirstRow);
Assert.AreEqual(2, firstTable.Rows.Count);
Assert.AreEqual(2, table.Rows.Count);
Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
}
}