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.




Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.document.importnode_overload_2.html

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

dstDoc.LastSection.Body.AppendChild(dstNode);

//Save output document

dstDoc.Save(@"Test139\out.doc");

Hope this helps.

Best regards.