java.lang.Object
com.aspose.words.MailMergeMainDocumentType
public class MailMergeMainDocumentType
- extends java.lang.Object
Utility class containing constants.
Specifies the possible types for a mail merge source document.
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.setDataSource(getArtifactsDir() + "Document.Lines.txt");
odso.setDataSourceType(OdsoDataSourceType.TEXT);
odso.setColumnDelimiter('|');
odso.setDataSource(getArtifactsDir() + "Document.Lines.txt");
odso.setFirstRowContainsColumnNames(true);
// ODSO objects can also be cloned
Assert.assertNotSame(odso, odso.deepClone());
// The mail merge will be performed when this document is opened
doc.save(getArtifactsDir() + "Document.MailMergeSettings.docx");
- See Also:
- MailMergeSettings.MainDocumentType
Field Summary |
static final int | NOT_A_MERGE_DOCUMENT = 0 | |
This document is not a mail merge document.
|
static final int | FORM_LETTERS = 1 | |
Specifies that the mail merge source document is of the form letter type.
|
static final int | MAILING_LABELS = 2 | |
Specifies that the mail merge source document is of the mailing label type.
|
static final int | ENVELOPES = 4 | |
Specifies that the mail merge source document is of the envelope type.
|
static final int | CATALOG = 8 | |
Specifies that the mail merge source document is of the catalog type.
|
static final int | EMAIL = 16 | |
Specifies that the mail merge source document is of the e-mail message type.
|
static final int | FAX = 32 | |
Specifies that the mail merge source document is of the fax type.
|
static final int | DEFAULT = 0 | |
Equals to NOT_A_MERGE_DOCUMENT |
NOT_A_MERGE_DOCUMENT = 0 | |
public static final int NOT_A_MERGE_DOCUMENT |
-
This document is not a mail merge document.
FORM_LETTERS = 1 | |
public static final int FORM_LETTERS |
-
Specifies that the mail merge source document is of the form letter type.
MAILING_LABELS = 2 | |
public static final int MAILING_LABELS |
-
Specifies that the mail merge source document is of the mailing label type.
ENVELOPES = 4 | |
public static final int ENVELOPES |
-
Specifies that the mail merge source document is of the envelope type.
CATALOG = 8 | |
public static final int CATALOG |
-
Specifies that the mail merge source document is of the catalog type.
EMAIL = 16 | |
public static final int EMAIL |
-
Specifies that the mail merge source document is of the e-mail message type.
FAX = 32 | |
public static final int FAX |
-
Specifies that the mail merge source document is of the fax type.
DEFAULT = 0 | |
public static final int DEFAULT |
-
Equals to NOT_A_MERGE_DOCUMENT
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.