MailMergeCleanupOptions

Inheritance: java.lang.Object

public class MailMergeCleanupOptions

Specifies options that determine what items are removed during mail merge.

Examples:

Shows how to automatically remove unmerged merge fields during mail merge.


 doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
 

Shows how to make sure empty paragraphs that result from merging fields with no data are removed from the document.


 doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
 

Shows how to instruct the mail merge engine to remove any containing fields from around a merge field during mail merge.


 doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
 

Shows how to remove whole empty table during mail merge.


 DataTable tableCustomers = new DataTable("A");
 tableCustomers.getColumns().add("CustomerID");
 tableCustomers.getColumns().add("CustomerName");
 tableCustomers.getRows().add(new Object[] { 1, "John Doe" });
 tableCustomers.getRows().add(new Object[] { 2, "Jane Doe" });

 DataSet ds = new DataSet();
 ds.getTables().add(tableCustomers);

 Document doc = new Document(getMyDir() + "Mail merge tables.docx");
 Assert.assertEquals(2, doc.getChildNodes(NodeType.TABLE, true).getCount());

 doc.getMailMerge().setMergeDuplicateRegions(false);
 doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_TABLES | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);
 doc.getMailMerge().executeWithRegions(ds.getTables().get("A"));

 doc.save(getArtifactsDir() + "MailMerge.RemoveEmptyTables.docx");

 doc = new Document(getArtifactsDir() + "MailMerge.RemoveEmptyTables.docx");
 Assert.assertEquals(1, doc.getChildNodes(NodeType.TABLE, true).getCount());
 

Fields

FieldDescription
NONESpecifies a default value.
REMOVE_CONTAINING_FIELDSSpecifies whether fields that contain merge fields (for example, IFs) should be removed from the document if the nested merge fields are removed.
REMOVE_EMPTY_PARAGRAPHSSpecifies whether paragraphs that contained mail merge fields with no data should be removed from the document.
REMOVE_EMPTY_TABLESSpecifies whether to remove from the document tables that contain mail merge regions that were removed using either the REMOVE_UNUSED_REGIONS or the REMOVE_EMPTY_TABLE_ROWS option.
REMOVE_EMPTY_TABLE_ROWSSpecifies whether empty rows that contain mail merge regions should be removed from the document.
REMOVE_STATIC_FIELDSSpecifies whether static fields should be removed from the document.
REMOVE_UNUSED_FIELDSSpecifies whether unused merge fields should be removed from the document.
REMOVE_UNUSED_REGIONSSpecifies whether unused mail merge regions should be removed from the document.
length

Methods

MethodDescription
fromName(String mailMergeCleanupOptionsName)
fromNames(Set mailMergeCleanupOptionsNames)
getName(int mailMergeCleanupOptions)
getNames(int mailMergeCleanupOptions)
getValues()
toString(int mailMergeCleanupOptions)
toStringSet(int attr)

NONE

public static int NONE

Specifies a default value.

REMOVE_CONTAINING_FIELDS

public static int REMOVE_CONTAINING_FIELDS

Specifies whether fields that contain merge fields (for example, IFs) should be removed from the document if the nested merge fields are removed.

REMOVE_EMPTY_PARAGRAPHS

public static int REMOVE_EMPTY_PARAGRAPHS

Specifies whether paragraphs that contained mail merge fields with no data should be removed from the document. When this option is set, paragraphs which contain region start and end merge fields which are otherwise empty are also removed.

REMOVE_EMPTY_TABLES

public static int REMOVE_EMPTY_TABLES

Specifies whether to remove from the document tables that contain mail merge regions that were removed using either the REMOVE_UNUSED_REGIONS or the REMOVE_EMPTY_TABLE_ROWS option.

Remarks:

This option applies only to mail merge with regions.

REMOVE_EMPTY_TABLE_ROWS

public static int REMOVE_EMPTY_TABLE_ROWS

Specifies whether empty rows that contain mail merge regions should be removed from the document.

Remarks:

This option applies only to mail merge with regions.

REMOVE_STATIC_FIELDS

public static int REMOVE_STATIC_FIELDS

Specifies whether static fields should be removed from the document. Static fields are fields, which results remain the same upon any document change. Fields, which do not store their results in a document and are calculated on the fly (like FieldType.FIELD_LIST_NUM, FieldType.FIELD_SYMBOL, etc.) are not considered to be static.

Remarks:

Here is the full list of field types, which are not considered to be static:

REMOVE_UNUSED_FIELDS

public static int REMOVE_UNUSED_FIELDS

Specifies whether unused merge fields should be removed from the document.

REMOVE_UNUSED_REGIONS

public static int REMOVE_UNUSED_REGIONS

Specifies whether unused mail merge regions should be removed from the document.

Remarks:

This option applies only to mail merge with regions.

length

public static int length

fromName(String mailMergeCleanupOptionsName)

public static int fromName(String mailMergeCleanupOptionsName)

Parameters:

ParameterTypeDescription
mailMergeCleanupOptionsNamejava.lang.String

Returns: int

fromNames(Set mailMergeCleanupOptionsNames)

public static int fromNames(Set mailMergeCleanupOptionsNames)

Parameters:

ParameterTypeDescription
mailMergeCleanupOptionsNamesjava.util.Set

Returns: int

getName(int mailMergeCleanupOptions)

public static String getName(int mailMergeCleanupOptions)

Parameters:

ParameterTypeDescription
mailMergeCleanupOptionsint

Returns: java.lang.String

getNames(int mailMergeCleanupOptions)

public static Set getNames(int mailMergeCleanupOptions)

Parameters:

ParameterTypeDescription
mailMergeCleanupOptionsint

Returns: java.util.Set

getValues()

public static int[] getValues()

Returns: int[]

toString(int mailMergeCleanupOptions)

public static String toString(int mailMergeCleanupOptions)

Parameters:

ParameterTypeDescription
mailMergeCleanupOptionsint

Returns: java.lang.String

toStringSet(int attr)

public static String toStringSet(int attr)

Parameters:

ParameterTypeDescription
attrint

Returns: java.lang.String