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.

If Fields

The If field compares two values and then inserts the text appropriate to the result of the comparison.

When used in a mail merge main document, the If field can examine information in the merged data records, such as postal codes or account numbers.

Following example demonstrates how to perform a conditional mail merge by importing data from an instance of an anonymous type.

Screenshot
If Fields 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.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using GemBox.Document;
using GemBox.Document.MailMerging;

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("MergeIfFields.docx");

        var customer = new { Gender = "M", CustomerName = "John", Surname = "Doe" };

        document.MailMerge.Execute(customer);

        document.Save("If Fields.docx");
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.IO
Imports System.Linq
Imports GemBox.Document
Imports GemBox.Document.MailMerging

Module Samples

    Sub Main()

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

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

        Dim customer = New With {.Gender = "M", .CustomerName = "John", .Surname = "Doe"}

        document.MailMerge.Execute(customer)

        document.Save("If Fields.docx")

    End Sub

End Module

Check next sample.