Get Started
Usage API
More information

MailMerge

MailMerge([nStartIndex], [nEndIndex]) → { bool }

Starts the mail merge process.

Parameters:

Name Type Default Description
nStartIndex number 0

The start index of the document for mail merge process.

nEndIndex number Api.GetMailMergeReceptionsCount() - 1

The end index of the document for mail merge process.

Returns:

Type
bool

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var arrField = ["Greeting line", "First name", "Last name"];
for (let i = 0; i < 3; i++) {
    var oRun = Api.CreateRun();
    oRun.AddText(arrField[i]);
    oParagraph.AddElement(oRun);
    oRun.WrapInMailMergeField();
    oParagraph.AddText(" ");
}
oParagraph.AddText("!");
Api.LoadMailMergeData([arrField, ["Dear", "John", "Smith"], ["Hello", "Lara", "Davis"]]);
Api.MailMerge(1);
builder.SaveFile("docx", "MailMerge.docx");
builder.CloseFile();

Resulting document