com.aspose.words

Class MailMergeDestination

  • java.lang.Object
    • com.aspose.words.MailMergeDestination
public class MailMergeDestination 
extends java.lang.Object

Utility class containing constants. Specifies the possible results which may be generated when a mail merge is carried out on a document.

Example:

Shows how to execute an Office Data Source Object mail merge with MailMergeSettings.
// We'll create a simple document that will act as a destination for mail merge data
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.write("Dear ");
builder.insertField("MERGEFIELD FirstName", "<FirstName>");
builder.write(" ");
builder.insertField("MERGEFIELD LastName", "<LastName>");
builder.writeln(": ");
builder.insertField("MERGEFIELD Message", "<Message>");

// Also we'll need a data source, in this case it will be an ASCII text file
// We can use any character we want as a delimiter, in this case we'll choose '|'
// The delimiter character is selected in the ODSO settings of mail merge settings
String[] lines = {"FirstName|LastName|Message",
        "John|Doe|Hello! This message was created with Aspose Words mail merge."};
Files.write(Paths.get(getArtifactsDir() + "Document.Lines.txt"),
        (lines + System.lineSeparator()).getBytes(UTF_8),
        new StandardOpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.APPEND});

// Set the data source, query and other things
MailMergeSettings mailMergeSettings = doc.getMailMergeSettings();
mailMergeSettings.setMainDocumentType(MailMergeMainDocumentType.MAILING_LABELS);
mailMergeSettings.setCheckErrors(MailMergeCheckErrors.SIMULATE);
mailMergeSettings.setDataType(MailMergeDataType.NATIVE);
mailMergeSettings.setDataSource(getArtifactsDir() + "Document.Lines.txt");
mailMergeSettings.setQuery("SELECT * FROM " + doc.getMailMergeSettings().getDataSource());
mailMergeSettings.setLinkToQuery(true);
mailMergeSettings.setViewMergedData(true);

Assert.assertEquals(mailMergeSettings.getDestination(), MailMergeDestination.DEFAULT);
Assert.assertFalse(mailMergeSettings.getDoNotSupressBlankLines());

// Office Data Source Object settings
Odso odso = mailMergeSettings.getOdso();
odso.setDataSource(getArtifactsDir() + "Document.Lines.txt");
odso.setDataSourceType(OdsoDataSourceType.TEXT);
odso.setColumnDelimiter('|');
odso.setDataSource(getArtifactsDir() + "Document.Lines.txt");
odso.setFirstRowContainsColumnNames(true);

// ODSO/MailMergeSettings objects can also be cloned
Assert.assertNotSame(odso, odso.deepClone());
Assert.assertNotSame(mailMergeSettings, mailMergeSettings.deepClone());

// The mail merge will be performed when this document is opened
doc.save(getArtifactsDir() + "Document.MailMergeSettings.docx");
See Also:
MailMergeSettings.Destination

Field Summary
static final intNEW_DOCUMENT = 0
Specifies that conforming hosting applications shall generate new documents by populating the fields within a given document with data from the specified external data source.
static final intPRINTER = 1
Specifies that conforming hosting applications shall print the documents that result from populating the fields within a given document with external data from the specified external data source.
static final intEMAIL = 2
Specifies that conforming hosting applications shall generate emails using the documents that result from populating the fields within a given document with data from the specified external data source.
static final intFAX = 4
Specifies that conforming hosting applications shall generate faxes using the documents that result from populating the fields within a given document with data from the specified external data source.
static final intDEFAULT = 0
Equals to the NEW_DOCUMENT value.
 

    • Field Detail

      • NEW_DOCUMENT = 0

        public static final int NEW_DOCUMENT
        Specifies that conforming hosting applications shall generate new documents by populating the fields within a given document with data from the specified external data source.
      • PRINTER = 1

        public static final int PRINTER
        Specifies that conforming hosting applications shall print the documents that result from populating the fields within a given document with external data from the specified external data source.
      • EMAIL = 2

        public static final int EMAIL
        Specifies that conforming hosting applications shall generate emails using the documents that result from populating the fields within a given document with data from the specified external data source.
      • FAX = 4

        public static final int FAX
        Specifies that conforming hosting applications shall generate faxes using the documents that result from populating the fields within a given document with data from the specified external data source.
      • DEFAULT = 0

        public static final int DEFAULT
        Equals to the NEW_DOCUMENT value.