Aspose.Words.Examples.CSharp.Programming_Documents.Working_with_Tables.CloneTable.CloneLastRow C# (CSharp) Method

CloneLastRow() private static method

Shows how to clone last row of table.
private static CloneLastRow ( string dataDir ) : void
dataDir string
return void
        private static void CloneLastRow(string dataDir)
        {
            // ExStart:CloneLastRow
            Document doc = new Document(dataDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clone the last row in the table.
            Row clonedRow = (Row)table.LastRow.Clone(true);

            // Remove all content from the cloned row's cells. This makes the row ready for
            // New content to be inserted into.
            foreach (Cell cell in clonedRow.Cells)
                cell.RemoveAllChildren();

            // Add the row to the end of the table.
            table.AppendChild(clonedRow);

            dataDir = dataDir + "Table.AddCloneRowToTable_out.doc";
            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:CloneLastRow
            Console.WriteLine("\nTable last row cloned successfully.\nFile saved at " + dataDir);
        }
    }