If Fields
GemBox.Document provides support for conditional mail merging with IF fields.
By using IF fields you can compare two text values in the mail merge process and merge or insert the appropriate result text.
The following example shows how you can perform a conditional mail merge and get resolved IF field results.


using GemBox.Document;
class Program
{
static void Main()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var document = DocumentModel.Load("%InputFileName%");
var data = new
{
FirstName = "John",
LastName = "Doe",
Gender = "Male",
Age = 30
};
document.MailMerge.Execute(data);
document.Save("Merged If Fields Output.%OutputFileType%");
}
}
Imports GemBox.Document
Module Program
Sub Main()
' If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Dim document = DocumentModel.Load("%InputFileName%")
Dim data = New With
{
.FirstName = "John",
.LastName = "Doe",
.Gender = "Male",
.Age = 30
}
document.MailMerge.Execute(data)
document.Save("Merged If Fields Output.%OutputFileType%")
End Sub
End Module
The IF field's code has the following syntax:
{ IF "Value1" Operator "Value2" "TrueText" "FalseText" }
Each part, except Operator
, can contain text and other Field
elements. After executing a mail merge process, the result is either TrueText
or <FalseText
, based on the used comparison operator.
Operator | Description |
---|---|
= | Equal |
<> | Not equal |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
Want more?
Like it?
Published: December 13, 2018 | Modified: September 10, 2020 | Author: Damir Stipinovic