Aspose::Words::MailMerging::FieldMergingArgsBase Class Reference

Detailed Description

Base class for FieldMergingArgs and ImageFieldMergingArgs.

See also
Aspose::Words::MailMerging::FieldMergingArgs
Aspose::Words::MailMerging::ImageFieldMergingArgs
Examples

Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.

void MergeHtml()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertField(u"MERGEFIELD html_Title \\b Content");
builder->InsertField(u"MERGEFIELD html_Body \\b Content");
ArrayPtr<SharedPtr<System::Object>> mergeData = MakeArray<SharedPtr<System::Object>>(
{System::ObjectExt::Box<String>(String(u"<html>") + u"<h1>" + u"<span style=\"color: #0000ff; font-family: Arial;\">Hello World!</span>" +
u"</h1>" + u"</html>"),
System::ObjectExt::Box<String>(
String(u"<html>") + u"<blockquote>" +
u"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>" +
u"</blockquote>" + u"</html>")});
doc->get_MailMerge()->set_FieldMergingCallback(MakeObject<ExMailMergeEvent::HandleMergeFieldInsertHtml>());
doc->get_MailMerge()->Execute(MakeArray<String>({u"html_Title", u"html_Body"}), mergeData);
doc->Save(ArtifactsDir + u"MailMergeEvent.MergeHtml.docx");
}
class HandleMergeFieldInsertHtml : public IFieldMergingCallback
{
public:
void FieldMerging(SharedPtr<FieldMergingArgs> args) override
{
if (args->get_DocumentFieldName().StartsWith(u"html_") && args->get_Field()->GetFieldCode().Contains(u"\\b"))
{
// Add parsed HTML data to the document's body.
auto builder = MakeObject<DocumentBuilder>(args->get_Document());
builder->MoveToMergeField(args->get_DocumentFieldName());
builder->InsertHtml(System::ObjectExt::Unbox<String>(args->get_FieldValue()));
// Since we have already inserted the merged content manually,
// we will not need to respond to this event by returning content via the "Text" property.
args->set_Text(String::Empty);
}
}
void ImageFieldMerging(SharedPtr<ImageFieldMergingArgs> args) override
{
// Do nothing.
}
};

#include <Aspose.Words.Cpp/MailMerging/FieldMergingArgsBase.h>

+ Inheritance diagram for Aspose::Words::MailMerging::FieldMergingArgsBase:

Public Member Functions

SharedPtr< Documentget_Document () const
 Returns the Document object for which the mail merge is performed. More...
 
String get_DocumentFieldName () const
 Gets the name of the merge field as specified in the document. More...
 
SharedPtr< FieldMergeFieldget_Field () const
 Gets the object that represents the current merge field. More...
 
String get_FieldName () const
 Gets the name of the merge field in the data source. More...
 
SharedPtr< Objectget_FieldValue () const
 Gets the value of the field from the data source. More...
 
int32_t get_RecordIndex () const
 Gets the zero based index of the record that is being merged. More...
 
String get_TableName () const
 Gets the name of the data table for the current merge operation or empty string if the name is not available. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_FieldValue (SharedPtr< Object > value)
 Sets the value of the field from the data source. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_Document()

System::SharedPtr<Aspose::Words::Document> Aspose::Words::MailMerging::FieldMergingArgsBase::get_Document ( ) const

Returns the Document object for which the mail merge is performed.

Examples

Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.

void MergeHtml()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertField(u"MERGEFIELD html_Title \\b Content");
builder->InsertField(u"MERGEFIELD html_Body \\b Content");
ArrayPtr<SharedPtr<System::Object>> mergeData = MakeArray<SharedPtr<System::Object>>(
{System::ObjectExt::Box<String>(String(u"<html>") + u"<h1>" + u"<span style=\"color: #0000ff; font-family: Arial;\">Hello World!</span>" +
u"</h1>" + u"</html>"),
System::ObjectExt::Box<String>(
String(u"<html>") + u"<blockquote>" +
u"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>" +
u"</blockquote>" + u"</html>")});
doc->get_MailMerge()->set_FieldMergingCallback(MakeObject<ExMailMergeEvent::HandleMergeFieldInsertHtml>());
doc->get_MailMerge()->Execute(MakeArray<String>({u"html_Title", u"html_Body"}), mergeData);
doc->Save(ArtifactsDir + u"MailMergeEvent.MergeHtml.docx");
}
class HandleMergeFieldInsertHtml : public IFieldMergingCallback
{
public:
void FieldMerging(SharedPtr<FieldMergingArgs> args) override
{
if (args->get_DocumentFieldName().StartsWith(u"html_") && args->get_Field()->GetFieldCode().Contains(u"\\b"))
{
// Add parsed HTML data to the document's body.
auto builder = MakeObject<DocumentBuilder>(args->get_Document());
builder->MoveToMergeField(args->get_DocumentFieldName());
builder->InsertHtml(System::ObjectExt::Unbox<String>(args->get_FieldValue()));
// Since we have already inserted the merged content manually,
// we will not need to respond to this event by returning content via the "Text" property.
args->set_Text(String::Empty);
}
}
void ImageFieldMerging(SharedPtr<ImageFieldMergingArgs> args) override
{
// Do nothing.
}
};

◆ get_DocumentFieldName()

System::String Aspose::Words::MailMerging::FieldMergingArgsBase::get_DocumentFieldName ( ) const

Gets the name of the merge field as specified in the document.

If you have a mapping from a document field name to a different data source field name, then this is the original field name as specified in the document.

If you specified a field name prefix, for example "Image:MyFieldName" in the document, then DocumentFieldName returns field name without the prefix, that is "MyFieldName".

Examples

Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.

void MergeHtml()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertField(u"MERGEFIELD html_Title \\b Content");
builder->InsertField(u"MERGEFIELD html_Body \\b Content");
ArrayPtr<SharedPtr<System::Object>> mergeData = MakeArray<SharedPtr<System::Object>>(
{System::ObjectExt::Box<String>(String(u"<html>") + u"<h1>" + u"<span style=\"color: #0000ff; font-family: Arial;\">Hello World!</span>" +
u"</h1>" + u"</html>"),
System::ObjectExt::Box<String>(
String(u"<html>") + u"<blockquote>" +
u"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>" +
u"</blockquote>" + u"</html>")});
doc->get_MailMerge()->set_FieldMergingCallback(MakeObject<ExMailMergeEvent::HandleMergeFieldInsertHtml>());
doc->get_MailMerge()->Execute(MakeArray<String>({u"html_Title", u"html_Body"}), mergeData);
doc->Save(ArtifactsDir + u"MailMergeEvent.MergeHtml.docx");
}
class HandleMergeFieldInsertHtml : public IFieldMergingCallback
{
public:
void FieldMerging(SharedPtr<FieldMergingArgs> args) override
{
if (args->get_DocumentFieldName().StartsWith(u"html_") && args->get_Field()->GetFieldCode().Contains(u"\\b"))
{
// Add parsed HTML data to the document's body.
auto builder = MakeObject<DocumentBuilder>(args->get_Document());
builder->MoveToMergeField(args->get_DocumentFieldName());
builder->InsertHtml(System::ObjectExt::Unbox<String>(args->get_FieldValue()));
// Since we have already inserted the merged content manually,
// we will not need to respond to this event by returning content via the "Text" property.
args->set_Text(String::Empty);
}
}
void ImageFieldMerging(SharedPtr<ImageFieldMergingArgs> args) override
{
// Do nothing.
}
};

◆ get_Field()

System::SharedPtr<Aspose::Words::Fields::FieldMergeField> Aspose::Words::MailMerging::FieldMergingArgsBase::get_Field ( ) const

Gets the object that represents the current merge field.

Examples

Shows how to execute a mail merge with a custom callback that handles merge data in the form of HTML documents.

void MergeHtml()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertField(u"MERGEFIELD html_Title \\b Content");
builder->InsertField(u"MERGEFIELD html_Body \\b Content");
ArrayPtr<SharedPtr<System::Object>> mergeData = MakeArray<SharedPtr<System::Object>>(
{System::ObjectExt::Box<String>(String(u"<html>") + u"<h1>" + u"<span style=\"color: #0000ff; font-family: Arial;\">Hello World!</span>" +
u"</h1>" + u"</html>"),
System::ObjectExt::Box<String>(
String(u"<html>") + u"<blockquote>" +
u"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>" +
u"</blockquote>" + u"</html>")});
doc->get_MailMerge()->set_FieldMergingCallback(MakeObject<ExMailMergeEvent::HandleMergeFieldInsertHtml>());
doc->get_MailMerge()->Execute(MakeArray<String>({u"html_Title", u"html_Body"}), mergeData);
doc->Save(ArtifactsDir + u"MailMergeEvent.MergeHtml.docx");
}
class HandleMergeFieldInsertHtml : public IFieldMergingCallback
{
public:
void FieldMerging(SharedPtr<FieldMergingArgs> args) override
{
if (args->get_DocumentFieldName().StartsWith(u"html_") && args->get_Field()->GetFieldCode().Contains(u"\\b"))
{
// Add parsed HTML data to the document's body.
auto builder = MakeObject<DocumentBuilder>(args->get_Document());
builder->MoveToMergeField(args->get_DocumentFieldName());
builder->InsertHtml(System::ObjectExt::Unbox<String>(args->get_FieldValue()));
// Since we have already inserted the merged content manually,
// we will not need to respond to this event by returning content via the "Text" property.
args->set_Text(String::Empty);
}
}
void ImageFieldMerging(SharedPtr<ImageFieldMergingArgs> args) override
{
// Do nothing.
}
};

◆ get_FieldName()

System::String Aspose::Words::MailMerging::FieldMergingArgsBase::get_FieldName ( ) const

Gets the name of the merge field in the data source.

If you have a mapping from a document field name to a different data source field name, then this is the mapped field name.

If you specified a field name prefix, for example "Image:MyFieldName" in the document, then FieldName returns field name without the prefix, that is "MyFieldName".

◆ get_FieldValue()

System::SharedPtr<System::Object> Aspose::Words::MailMerging::FieldMergingArgsBase::get_FieldValue ( ) const

Gets the value of the field from the data source.

◆ get_RecordIndex()

int32_t Aspose::Words::MailMerging::FieldMergingArgsBase::get_RecordIndex ( ) const

Gets the zero based index of the record that is being merged.

◆ get_TableName()

System::String Aspose::Words::MailMerging::FieldMergingArgsBase::get_TableName ( ) const

Gets the name of the data table for the current merge operation or empty string if the name is not available.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::MailMerging::FieldMergingArgsBase::GetType ( ) const
overridevirtual

◆ Is()

virtual bool Aspose::Words::MailMerging::FieldMergingArgsBase::Is ( const System::TypeInfo target) const
overridevirtual

◆ set_FieldValue()

void Aspose::Words::MailMerging::FieldMergingArgsBase::set_FieldValue ( System::SharedPtr< System::Object value)

Sets the value of the field from the data source.

◆ Type()

static const System::TypeInfo& Aspose::Words::MailMerging::FieldMergingArgsBase::Type ( )
static