com.aspose.words
Class MailMergeDataType

java.lang.Object
    extended by 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 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."};

String dataSrcFilename = getArtifactsDir() + "Document.MailMergeSettings.DataSource.txt";
Files.write(Paths.get(dataSrcFilename),
        (lines + System.lineSeparator()).getBytes(UTF_8),
        new StandardOpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.APPEND});

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

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

// Office Data Source Object settings
Odso odso = settings.getOdso();
odso.setDataSource(dataSrcFilename);
odso.setDataSourceType(OdsoDataSourceType.TEXT);
odso.setColumnDelimiter('|');
odso.setFirstRowContainsColumnNames(true);

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

// 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.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.