Class MailMergeCheckErrors

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

Utility class containing constants. Specifies how Microsoft Word will report errors detected during mail merge.


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.setDataSource(getArtifactsDir() + "Document.Lines.txt");
mailMergeSettings.setQuery("SELECT * FROM " + doc.getMailMergeSettings().getDataSource());

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

// Office Data Source Object settings
Odso odso = mailMergeSettings.getOdso();
odso.setDataSource(getArtifactsDir() + "Document.Lines.txt");
odso.setDataSource(getArtifactsDir() + "Document.Lines.txt");

// 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 + "Document.MailMergeSettings.docx");
See Also:

Field Summary
static final intSIMULATE = 1
Simulate the merge and report errors in a new document.
static final intPAUSE_ON_ERROR = 2
Complete the merge and pause to report errors.
static final intCOLLECT_ERRORS = 3
Complete the merge and report errors in a new document.
static final intDEFAULT = 2
Equals to the PAUSE_ON_ERROR value.

    • Field Detail

      • SIMULATE = 1

        public static final int SIMULATE
        Simulate the merge and report errors in a new document.
      • PAUSE_ON_ERROR = 2

        public static final int PAUSE_ON_ERROR
        Complete the merge and pause to report errors.
      • COLLECT_ERRORS = 3

        public static final int COLLECT_ERRORS
        Complete the merge and report errors in a new document.
      • DEFAULT = 2

        public static final int DEFAULT
        Equals to the PAUSE_ON_ERROR value.