com.aspose.words

Class MailMergeDataType

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

Utility class containing constants. Specifies the type of an external mail merge data source.

Example:

Shows how to execute a 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.setDataType(MailMergeDataType.NATIVE);
mailMergeSettings.setDataSource(getArtifactsDir() + "Document.Lines.txt");
mailMergeSettings.setQuery("SELECT * FROM " + doc.getMailMergeSettings().getDataSource());
mailMergeSettings.setLinkToQuery(true);
mailMergeSettings.setViewMergedData(true);

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

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

Field Summary
static final intNONE = -1
No mail merge data source is specified.
static final intTEXT_FILE = 0
Specifies that a given document has been connected to a text file via the Dynamic Data Exchange (DDE) system.
static final intDATABASE = 1
Specifies that a given document has been connected to an Access database via the Dynamic Data Exchange (DDE) system.
static final intSPREADSHEET = 2
Specifies that a given document has been connected to an Excel spreadsheet via the Dynamic Data Exchange (DDE) system.
static final intQUERY = 3
Specifies that a given document has been connected to an external data source using an external query tool.
static final intODBC = 4
Specifies that a given document has been connected to an external data source via the Open Database Connectivity interface.
static final intNATIVE = 5
Specifies that a given document has been connected to an external data source via the Office Data Source Object (ODSO) interface.
static final intDEFAULT = -1
Equals to NONE.
 

    • Field Detail

      • NONE = -1

        public static final int NONE
        No mail merge data source is specified.
      • TEXT_FILE = 0

        public static final int TEXT_FILE
        Specifies that a given document has been connected to a text file via the Dynamic Data Exchange (DDE) system.
      • DATABASE = 1

        public static final int DATABASE
        Specifies that a given document has been connected to an Access database via the Dynamic Data Exchange (DDE) system.
      • SPREADSHEET = 2

        public static final int SPREADSHEET
        Specifies that a given document has been connected to an Excel spreadsheet via the Dynamic Data Exchange (DDE) system.
      • QUERY = 3

        public static final int QUERY
        Specifies that a given document has been connected to an external data source using an external query tool.
      • ODBC = 4

        public static final int ODBC
        Specifies that a given document has been connected to an external data source via the Open Database Connectivity interface.
      • NATIVE = 5

        public static final int NATIVE
        Specifies that a given document has been connected to an external data source via the Office Data Source Object (ODSO) interface.
      • DEFAULT = -1

        public static final int DEFAULT
        Equals to NONE.