Get Started
Usage API
More information

GetMailMergeTemplateDocContent

GetMailMergeTemplateDocContent() → { ApiDocumentContent }

Returns the mail merge template document.

Parameters:

This method doesn't have any parameters.

Returns:

Type
ApiDocumentContent

Example

Copy code
builder.CreateFile("docx");
oDocument = Api.GetDocument();
oParagraph = oDocument.GetElement(0);
arrField = ["Greeting line", "First name", "Last name"];
for (let i = 0; i < 3; i++) {
    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"]]);
var oTemplateDocContent = Api.GetMailMergeTemplateDocContent();
var nReceptionsCount     = Api.GetMailMergeReceptionsCount();

arrReceptions = [];
for (var nReception = 0; nReception < nReceptionsCount; nReception++) 
{
    Api.MailMerge(nReception, nReception);
    oElement1 = oDocument.GetElement(0);
    arrReceptions.push(oElement1);
    Api.ReplaceDocumentContent(oTemplateDocContent);
}
oParagraph = Api.CreateParagraph();
oParagraph.AddLineBreak();
oParagraph.AddText("Receptions");
oParagraph.SetBold(true);
oDocument.Push(oParagraph);
oDocument.Push(arrReceptions[0]);
oDocument.Push(arrReceptions[1]);
oParagraph = Api.CreateParagraph();
oParagraph.AddLineBreak();
oParagraph.AddText("The mail merge process was run twice for each mail merge reception. But the results were replaced with the mail merge template document content. This template allows you to save each mail merge reception to the separate file.");
oDocument.Push(oParagraph);
builder.SaveFile("docx", "GetMailMergeTemplateDocContent.docx");
builder.CloseFile();

Resulting document