Represents the mail merge functionality.
For mail merge operation to work, the document should contain Word MERGEFIELD and optionally NEXT fields. During mail merge operation, merge fields in the document are replaced with values from your data source.
There are two distinct ways to use mail merge: with mail merge regions and without.
The simplest mail merge is without regions and it is very similar to how mail merge works in Word. Use Execute
methods to merge information from some data source such as DataTable, DataSet or an array of objects into your document. The MailMerge object processes all records of the data source and copies and appends content of the whole document for each record.
Note that when MailMerge object encounters a NEXT field, it selects next record in the data source and continues merging without copying any content.
Use ExecuteWithRegions
methods to merge information into a document with mail merge regions defined. You can use as data sources for this operation.
You need to use mail merge regions if you want to dynamically grow portions inside the document. Without mail merge regions whole document will be repeated for every record of the data source.
#include <Aspose.Words.Cpp/MailMerging/MailMerge.h>
Public Member Functions | |
void | DeleteFields () |
Removes mail merge related fields from the document. More... | |
void | Execute (const ArrayPtr< String > &fieldNames, const ArrayPtr< SharedPtr< Object > > &values) |
Performs a mail merge operation for a single record. More... | |
void | Execute (const SharedPtr< IMailMergeDataSource > &dataSource) |
Performs a mail merge from a custom data source. More... | |
void | ExecuteWithRegions (const SharedPtr< IMailMergeDataSource > &dataSource) |
Performs a mail merge from a custom data source with mail merge regions. More... | |
void | ExecuteWithRegions (const SharedPtr< IMailMergeDataSourceRoot > &dataSourceRoot) |
Performs a mail merge from a custom data source with mail merge regions. More... | |
MailMergeCleanupOptions | get_CleanupOptions () const |
Gets a set of flags that specify what items should be removed during mail merge. More... | |
bool | get_CleanupParagraphsWithPunctuationMarks () const |
Gets or sets a value indicating whether paragraphs with punctuation marks are considered as empty and should be removed if the RemoveEmptyParagraphs option is specified. More... | |
const SharedPtr< IFieldMergingCallback > & | get_FieldMergingCallback () const |
Occurs during mail merge when a mail merge field is encountered in the document. More... | |
const SharedPtr< IMailMergeCallback > & | get_MailMergeCallback () const |
Allows to handle particular events during mail merge. More... | |
SharedPtr< MappedDataFieldCollection > | get_MappedDataFields () |
Returns a collection that represents mapped data fields for the mail merge operation. More... | |
bool | get_MergeDuplicateRegions () const |
Gets a value indicating whether all of the document mail merge regions with the name of a data source should be merged while executing of a mail merge with regions against the data source or just the first one. More... | |
bool | get_MergeWholeDocument () const |
Gets a value indicating whether fields in whole document are updated while executing of a mail merge with regions. More... | |
bool | get_PreserveUnusedTags () const |
Gets a value indicating whether the unused "mustache" tags should be preserved. More... | |
String | get_RegionEndTag () const |
Gets or sets a mail merge region end tag. More... | |
String | get_RegionStartTag () const |
Gets or sets a mail merge region start tag. More... | |
bool | get_RestartListsAtEachSection () const |
Gets or sets a value indicating whether lists are restarted at each section after executing of a mail merge. More... | |
bool | get_RetainFirstSectionStart () const |
Gets a value indicating whether the SectionStart of the first document section and its copies for subsequent data source rows are retained during mail merge or updated according to MS Word behaviour. More... | |
bool | get_TrimWhitespaces () const |
Gets or sets a value indicating whether trailing and leading whitespaces are trimmed from mail merge values. More... | |
bool | get_UnconditionalMergeFieldsAndRegions () const |
Gets a value indicating whether merge fields and merge regions are merged regardless of the parent IF field's condition. More... | |
bool | get_UseNonMergeFields () const |
When true, specifies that in addition to MERGEFIELD fields, mail merge is performed into some other types of fields and also into "{{fieldName}}" tags. More... | |
bool | get_UseWholeParagraphAsRegion () const |
Gets a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region. More... | |
ArrayPtr< String > | GetFieldNames () |
Returns a collection of mail merge field names available in the document. More... | |
ArrayPtr< String > | GetFieldNamesForRegion (const String ®ionName) |
Returns a collection of mail merge field names available in the region. More... | |
ArrayPtr< String > | GetFieldNamesForRegion (const String ®ionName, int32_t regionIndex) |
Returns a collection of mail merge field names available in the region. More... | |
SharedPtr< IList< SharedPtr< MailMergeRegionInfo > > > | GetRegionsByName (const String ®ionName) |
Returns a collection of mail merge regions with the specified name. More... | |
SharedPtr< MailMergeRegionInfo > | GetRegionsHierarchy () |
Returns a full hierarchy of regions (with fields) available in the document. More... | |
virtual const TypeInfo & | GetType () const override |
virtual bool | Is (const TypeInfo &target) const override |
void | set_CleanupOptions (MailMergeCleanupOptions value) |
Sets a set of flags that specify what items should be removed during mail merge. More... | |
void | set_CleanupParagraphsWithPunctuationMarks (bool value) |
Setter for get_CleanupParagraphsWithPunctuationMarks. More... | |
void | set_FieldMergingCallback (const SharedPtr< IFieldMergingCallback > &value) |
Setter for get_FieldMergingCallback. More... | |
void | set_MailMergeCallback (const SharedPtr< IMailMergeCallback > &value) |
Allows to handle particular events during mail merge. More... | |
void | set_MergeDuplicateRegions (bool value) |
Sets a value indicating whether all of the document mail merge regions with the name of a data source should be merged while executing of a mail merge with regions against the data source or just the first one. More... | |
void | set_MergeWholeDocument (bool value) |
Sets a value indicating whether fields in whole document are updated while executing of a mail merge with regions. More... | |
void | set_PreserveUnusedTags (bool value) |
Sets a value indicating whether the unused "mustache" tags should be preserved. More... | |
void | set_RegionEndTag (const String &value) |
Setter for get_RegionEndTag. More... | |
void | set_RegionStartTag (const String &value) |
Setter for get_RegionStartTag. More... | |
void | set_RestartListsAtEachSection (bool value) |
Setter for get_RestartListsAtEachSection. More... | |
void | set_RetainFirstSectionStart (bool value) |
Sets a value indicating whether the SectionStart of the first document section and its copies for subsequent data source rows are retained during mail merge or updated according to MS Word behaviour. More... | |
void | set_TrimWhitespaces (bool value) |
Setter for get_TrimWhitespaces. More... | |
void | set_UnconditionalMergeFieldsAndRegions (bool value) |
Sets a value indicating whether merge fields and merge regions are merged regardless of the parent IF field's condition. More... | |
void | set_UseNonMergeFields (bool value) |
Setter for get_UseNonMergeFields. More... | |
void | set_UseWholeParagraphAsRegion (bool value) |
Sets a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region. More... | |
Static Public Member Functions | |
static const TypeInfo & | Type () |
void Aspose::Words::MailMerging::MailMerge::DeleteFields | ( | ) |
Removes mail merge related fields from the document.
This method removes MERGEFIELD and NEXT fields from the document.
This method could be useful if your mail merge operation does not always need to populate all fields in the document. Use this method to remove all remaining mail merge fields.
Shows how to delete all MERGEFIELDs from a document.
void Aspose::Words::MailMerging::MailMerge::Execute | ( | const System::ArrayPtr< System::String > & | fieldNames, |
const System::ArrayPtr< System::SharedPtr< System::Object > > & | values | ||
) |
Performs a mail merge operation for a single record.
Use this method to fill mail merge fields in the document with values from an array of objects.
This method merges data for one record only. The array of field names and the array of values represent the data of a single record.
This method does not use mail merge regions.
This method ignores the RemoveUnusedRegions option.
fieldNames | Array of merge field names. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored. |
values | Array of values to be inserted into the merge fields. Number of elements in this array must be the same as the number of elements in fieldNames. |
Shows how to merge an image from a URI as mail merge data into a MERGEFIELD.
void Aspose::Words::MailMerging::MailMerge::Execute | ( | const System::SharedPtr< Aspose::Words::MailMerging::IMailMergeDataSource > & | dataSource | ) |
Performs a mail merge from a custom data source.
Use this method to fill mail merge fields in the document with values from any data source such as a list or hashtable or objects. You need to write your own class that implements the IMailMergeDataSource interface.
You can use this method only when IsBidiTextSupportedOnUpdate is false, that is you do not need Right-To-Left language (such as Arabic or Hebrew) compatibility.
This method ignores the RemoveUnusedRegions option.
dataSource | An object that implements the custom mail merge data source interface. |
Shows how to execute a mail merge with a data source in the form of a custom object.
void Aspose::Words::MailMerging::MailMerge::ExecuteWithRegions | ( | const System::SharedPtr< Aspose::Words::MailMerging::IMailMergeDataSource > & | dataSource | ) |
Performs a mail merge from a custom data source with mail merge regions.
Use this method to fill mail merge fields in the document with values from any custom data source such as an XML file or collections of business objects. You need to write your own class that implements the IMailMergeDataSource interface.
You can use this method only when IsBidiTextSupportedOnUpdate is false, that is you do not need Right-To-Left language (such as Arabic or Hebrew) compatibility.
dataSource | An object that implements the custom mail merge data source interface. |
Shows how to use mail merge regions to execute a nested mail merge.
void Aspose::Words::MailMerging::MailMerge::ExecuteWithRegions | ( | const System::SharedPtr< Aspose::Words::MailMerging::IMailMergeDataSourceRoot > & | dataSourceRoot | ) |
Performs a mail merge from a custom data source with mail merge regions.
Use this method to fill mail merge fields in the document with values from any custom data source such as an XML file or collections of business objects. You need to write your own classes that implement the IMailMergeDataSourceRoot and IMailMergeDataSource interfaces.
You can use this method only when IsBidiTextSupportedOnUpdate is false, that is you do not need Right-To-Left language (such as Arabic or Hebrew) compatibility.
dataSourceRoot | An object that implements the custom mail merge data source root interface. |
Performs mail merge from a custom data source with master-detail data.
Aspose::Words::MailMerging::MailMergeCleanupOptions Aspose::Words::MailMerging::MailMerge::get_CleanupOptions | ( | ) | const |
Gets a set of flags that specify what items should be removed during mail merge.
bool Aspose::Words::MailMerging::MailMerge::get_CleanupParagraphsWithPunctuationMarks | ( | ) | const |
Gets or sets a value indicating whether paragraphs with punctuation marks are considered as empty and should be removed if the RemoveEmptyParagraphs option is specified.
The default value is true
. Here is the complete list of cleanable punctuation marks:
Shows how to remove paragraphs with punctuation marks after a mail merge operation.
const System::SharedPtr< Aspose::Words::MailMerging::IFieldMergingCallback > & Aspose::Words::MailMerging::MailMerge::get_FieldMergingCallback | ( | ) | const |
Occurs during mail merge when a mail merge field is encountered in the document.
Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.
const System::SharedPtr< Aspose::Words::MailMerging::IMailMergeCallback > & Aspose::Words::MailMerging::MailMerge::get_MailMergeCallback | ( | ) | const |
Allows to handle particular events during mail merge.
System::SharedPtr< Aspose::Words::MailMerging::MappedDataFieldCollection > Aspose::Words::MailMerging::MailMerge::get_MappedDataFields | ( | ) |
Returns a collection that represents mapped data fields for the mail merge operation.
Mapped data fields allow to automatically map between names of fields in your data source and names of mail merge fields in the document.
bool Aspose::Words::MailMerging::MailMerge::get_MergeDuplicateRegions | ( | ) | const |
Gets a value indicating whether all of the document mail merge regions with the name of a data source should be merged while executing of a mail merge with regions against the data source or just the first one.
bool Aspose::Words::MailMerging::MailMerge::get_MergeWholeDocument | ( | ) | const |
Gets a value indicating whether fields in whole document are updated while executing of a mail merge with regions.
bool Aspose::Words::MailMerging::MailMerge::get_PreserveUnusedTags | ( | ) | const |
Gets a value indicating whether the unused "mustache" tags should be preserved.
System::String Aspose::Words::MailMerging::MailMerge::get_RegionEndTag | ( | ) | const |
Gets or sets a mail merge region end tag.
Shows how to create, list, and read mail merge regions.
System::String Aspose::Words::MailMerging::MailMerge::get_RegionStartTag | ( | ) | const |
Gets or sets a mail merge region start tag.
Shows how to create, list, and read mail merge regions.
bool Aspose::Words::MailMerging::MailMerge::get_RestartListsAtEachSection | ( | ) | const |
Gets or sets a value indicating whether lists are restarted at each section after executing of a mail merge.
Shows how to control whether or not list numbering is restarted at each section when mail merge is performed.
bool Aspose::Words::MailMerging::MailMerge::get_RetainFirstSectionStart | ( | ) | const |
Gets a value indicating whether the SectionStart of the first document section and its copies for subsequent data source rows are retained during mail merge or updated according to MS Word behaviour.
bool Aspose::Words::MailMerging::MailMerge::get_TrimWhitespaces | ( | ) | const |
Gets or sets a value indicating whether trailing and leading whitespaces are trimmed from mail merge values.
Shows how to trim whitespaces from values of a data source while executing a mail merge.
bool Aspose::Words::MailMerging::MailMerge::get_UnconditionalMergeFieldsAndRegions | ( | ) | const |
Gets a value indicating whether merge fields and merge regions are merged regardless of the parent IF field's condition.
bool Aspose::Words::MailMerging::MailMerge::get_UseNonMergeFields | ( | ) | const |
When true, specifies that in addition to MERGEFIELD fields, mail merge is performed into some other types of fields and also into "{{fieldName}}" tags.
Normally, mail merge is only performed into MERGEFIELD fields, but several customers had their reporting built using other fields and had many documents created this way. To simplify migration (and because this approach was independently used by several customers) the ability to mail merge into other fields was introduced.
When UseNonMergeFields is set to true, Aspose.Words will perform mail merge into the following fields:
MERGEFIELD FieldName
MACROBUTTON NOMACRO FieldName
IF 0 = 0 "{FieldName}" ""
Also, when UserNonMergeFields is set to true, Aspose.Words will perform mail merge into text tags "{{fieldName}}". These are not fields, but just text tags.
bool Aspose::Words::MailMerging::MailMerge::get_UseWholeParagraphAsRegion | ( | ) | const |
Gets a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region.
System::ArrayPtr< System::String > Aspose::Words::MailMerging::MailMerge::GetFieldNames | ( | ) |
Returns a collection of mail merge field names available in the document.
Returns full merge field names including optional prefix. Does not eliminate duplicate field names.
A new string[] array is created on every call.
Includes "mustache" field names if UseNonMergeFields is true.
System::ArrayPtr< System::String > Aspose::Words::MailMerging::MailMerge::GetFieldNamesForRegion | ( | const System::String & | regionName | ) |
Returns a collection of mail merge field names available in the region.
Returns full merge field names including optional prefix. Does not eliminate duplicate field names.
If document contains multiple regions with the same name the very first region is processed.
A new string array is created on every call.
regionName | Region name (case-insensitive). |
Shows how to create, list, and read mail merge regions.
System::ArrayPtr< System::String > Aspose::Words::MailMerging::MailMerge::GetFieldNamesForRegion | ( | const System::String & | regionName, |
int32_t | regionIndex | ||
) |
Returns a collection of mail merge field names available in the region.
Returns full merge field names including optional prefix. Does not eliminate duplicate field names.
If document contains multiple regions with the same name the Nth region (zero-based) is processed.
A new string array is created on every call.
regionName | Region name (case-insensitive). |
regionIndex | Region index (zero-based). |
Shows how to create, list, and read mail merge regions.
System::SharedPtr< System::Collections::Generic::IList< System::SharedPtr< Aspose::Words::MailMerging::MailMergeRegionInfo > > > Aspose::Words::MailMerging::MailMerge::GetRegionsByName | ( | const System::String & | regionName | ) |
Returns a collection of mail merge regions with the specified name.
regionName | Region name (case-insensitive). |
Shows how to create, list, and read mail merge regions.
System::SharedPtr< Aspose::Words::MailMerging::MailMergeRegionInfo > Aspose::Words::MailMerging::MailMerge::GetRegionsHierarchy | ( | ) |
Returns a full hierarchy of regions (with fields) available in the document.
Hierarchy is returned in the form of the MailMergeRegionInfo class.
Shows how to verify mail merge regions.
|
overridevirtual |
Reimplemented from System::Object.
|
overridevirtual |
Reimplemented from System::Object.
void Aspose::Words::MailMerging::MailMerge::set_CleanupOptions | ( | Aspose::Words::MailMerging::MailMergeCleanupOptions | value | ) |
Sets a set of flags that specify what items should be removed during mail merge.
void Aspose::Words::MailMerging::MailMerge::set_CleanupParagraphsWithPunctuationMarks | ( | bool | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_FieldMergingCallback | ( | const System::SharedPtr< Aspose::Words::MailMerging::IFieldMergingCallback > & | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_MailMergeCallback | ( | const System::SharedPtr< Aspose::Words::MailMerging::IMailMergeCallback > & | value | ) |
Allows to handle particular events during mail merge.
void Aspose::Words::MailMerging::MailMerge::set_MergeDuplicateRegions | ( | bool | value | ) |
Sets a value indicating whether all of the document mail merge regions with the name of a data source should be merged while executing of a mail merge with regions against the data source or just the first one.
void Aspose::Words::MailMerging::MailMerge::set_MergeWholeDocument | ( | bool | value | ) |
Sets a value indicating whether fields in whole document are updated while executing of a mail merge with regions.
void Aspose::Words::MailMerging::MailMerge::set_PreserveUnusedTags | ( | bool | value | ) |
Sets a value indicating whether the unused "mustache" tags should be preserved.
void Aspose::Words::MailMerging::MailMerge::set_RegionEndTag | ( | const System::String & | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_RegionStartTag | ( | const System::String & | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_RestartListsAtEachSection | ( | bool | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_RetainFirstSectionStart | ( | bool | value | ) |
Sets a value indicating whether the SectionStart of the first document section and its copies for subsequent data source rows are retained during mail merge or updated according to MS Word behaviour.
void Aspose::Words::MailMerging::MailMerge::set_TrimWhitespaces | ( | bool | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_UnconditionalMergeFieldsAndRegions | ( | bool | value | ) |
Sets a value indicating whether merge fields and merge regions are merged regardless of the parent IF field's condition.
void Aspose::Words::MailMerging::MailMerge::set_UseNonMergeFields | ( | bool | value | ) |
void Aspose::Words::MailMerging::MailMerge::set_UseWholeParagraphAsRegion | ( | bool | value | ) |
Sets a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region.
|
static |