We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy table from one Word Doc to another

I have 2 Word docs, doc 1 and doc 2, and I would like to copy the table in doc 1 to doc 2. Doc 1 has two tables and I would like to copy the second table. How would I be able to do this.


Thanks for your inquiry. You should use ImportNode method to copy nodes from one document to another. Please see the following link for more information.
Also the following code shows how you can copy table from one document to another.

// Open sorse and destination documents
Document srcDoc = new Document(@"Test139\src.doc");
Document dstDoc = new Document(@"Test139\dst.doc");
// Get collection of Tables from the source document
NodeCollection tables = srcDoc.GetChildNodes(NodeType.Table, true);
// Get the secont table
Node secondTable = tables[1];
// Import this table into the destination document
Node dstNode = dstDoc.ImportNode(secondTable, true, ImportFormatMode.KeepSourceFormatting);
// Insert table into the destination document
// Save output document

Hope this helps.
Best regards.