GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Importing

Document element instances from one document instance cannot be inserted to another document instance. They must first be imported to another document, and then the imported elements can be inserted.

Following example shows how to import a document element into another document.

Screenshot
Importing Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.IO;
using System.Linq;
using System.Text;
using GemBox.Document;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("Invoice.docx");

        string pathToFileDirectory = "Resources";

        DocumentModel sourceDocument = DocumentModel.Load(Path.Combine(pathToFileDirectory, "Reading.docx"), LoadOptions.DocxDefault);

        // Reuse same mapping for importing all sections to improve performance.
        var mapping = new ImportMapping(sourceDocument, document, false);

        // Import all sections from source document.
        foreach (Section sourceSection in sourceDocument.Sections)
        {
            Section destinationSection = document.Import(sourceSection, true, mapping);
            document.Sections.Add(destinationSection);
        }

        document.Save("Importing.docx");
    }
}
Imports System
Imports System.IO
Imports System.Linq
Imports System.Text
Imports GemBox.Document

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("Invoice.docx")

        Dim pathToFileDirectory As String = "Resources"

        Dim sourceDocument As DocumentModel = DocumentModel.Load(Path.Combine(pathToFileDirectory, "Reading.docx"), LoadOptions.DocxDefault)

        ' Reuse same mapping for importing all sections to improve performance.
        Dim mapping = New ImportMapping(sourceDocument, document, False)

        ' Import all sections from source document.
        For Each sourceSection As Section In sourceDocument.Sections
            Dim destinationSection As Section = document.Import(sourceSection, True, mapping)
            document.Sections.Add(destinationSection)
        Next

        document.Save("Importing.docx")

    End Sub

End Module

Check next sample.