I’m trying to merge two documents. I’d like the second document to be inserted at a particular location in the master document. I’ve used a bookmark to mark the spot. When it goes in, I’d like the numbering scheme in place to account for the new section. Both documents have exactly the same styles.
I began with some sample code from this site. But the code appends the new document, it does not insert the new document at an arbitrary location.
Thanks in advance!
private void button1_Click(object sender, System.EventArgs e)
{
Aspose.Words.Document master_document;
Aspose.Words.Document child_document;
Aspose.Words.DocumentBuilder builder;
master_document = new Document("master.doc");
child_document = new Document("child.doc");
builder = new DocumentBuilder(master_document);
builder.MoveToBookmark("CHILDDOC");
AppendDoc(master_document, child_document);
master_document.Save("final.doc", Aspose.Words.SaveFormat.FormatDocument);
}
public void AppendDoc(Document dstDoc, Document srcDoc)
{
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
foreach (Section srcSection in srcDoc)
{
// Because we are copying a section from one document to another,
// it is required to import the Section node into the destination document.
// This adjusts any document-specific references to styles, lists, etc.
//
// Importing a node creates a copy of the original node, but the copy
// is ready to be inserted into the destination document.
Node dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);
// Now the new section node can be appended to the destination document.
dstDoc.AppendChild(dstSection);
}
}