DocumentBuilderInsertDocument Method (Document, ImportFormatMode, ImportFormatOptions)
Inserts a document at the cursor position.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.8
Syntax
public Node InsertDocument(
	Document srcDoc,
	ImportFormatMode importFormatMode,
	ImportFormatOptions importFormatOptions
)

Parameters

srcDoc
Type: Aspose.WordsDocument
Source document for inserting.
importFormatMode
Type: Aspose.WordsImportFormatMode
Specifies how to merge style formatting that clashes.
importFormatOptions
Type: Aspose.WordsImportFormatOptions
Allows to specify options that affect formatting of a result document.

Return Value

Type: Node
First node of the inserted content.
Remarks
This method mimics the MS Word behavior, as if CTRL+'A' (select all content) was pressed, then CTRL+'C' (copy selected into the buffer) inside one document and then CTRL+'V' (insert content from the buffer) inside another document.
Examples
Shows how to resolve styles behavior while inserting documents.
[C#]

Document destDoc = new Document(MyDir + "DocumentBuilder.SmartStyleBehavior.DestinationDocument.docx");
Document sourceDoc1 = new Document(MyDir + "DocumentBuilder.SmartStyleBehavior.SourceDocument01.docx");
Document sourceDoc2 = new Document(MyDir + "DocumentBuilder.SmartStyleBehavior.SourceDocument02.docx");

DocumentBuilder builder = new DocumentBuilder(destDoc);

builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.PageBreak);
builder.MoveToDocumentEnd();

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.SmartStyleBehavior = true;

// When SmartStyleBehavior is enabled,
// a source style will be expanded into a direct attributes inside a destination document,
// if KeepSourceFormatting importing mode is used.
builder.InsertDocument(sourceDoc1, ImportFormatMode.KeepSourceFormatting, importFormatOptions);

builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.PageBreak);

// When SmartStyleBehavior is disabled,
// a source style will be expanded only if it is numbered.
// Existing destination attributes will not be overridden, including lists.
builder.InsertDocument(sourceDoc2, ImportFormatMode.UseDestinationStyles);

destDoc.Save(ArtifactsDir + @"DocumentBuilder.SmartStyleBehavior.ResultDocument.docx");
See Also