We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge : apply custom formatting and word formatting

Hello,


I have a document with field for merging.
Some fields contains informations about MergeFormat from Word such as :

MERGEFIELD town * FirstCap \b " - "

But, if I set a callback for the merge, if I modify the value for “town”, the Merging format herited from word is not applied.

if the value for town is "my town"

In the callback :

1. the word format is applied
if (e.FieldName == “town”)
{
return;
}
I have “My town”.

// here, the word formatting is not applied
if (e.FieldName == “town”)
{
e.Text = "tatitatatoto " + e.FieldValue;
}
return;
I would like to have “Tatitatatoto my town”.

How can I do to apply the word formatting after my modifications with the merging callback ?

Thanks by advance.
Regards.

Hi Edwige,

Thanks for your inquiry. Implement IFieldMergingCallback interface if you want to control how data is inserted into merge fields during a mail merge operation. In your case, the FirstCap switch does not work. I suggest you following solution for your scenario.


void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)

{

if (e.DocumentFieldName == "town")

{

if (e.Field.GetFieldCode().Contains("FirstCap"))

{

string s = "tatitatatoto " + e.FieldValue.ToString();

e.Text = char.ToUpper(s[0]) + s.Substring(1);

}

}

}


Hope this helps you. Please let us know if you have any more queries.

Hello,


Thanks for your answer.
There is no way to keep the word formatting after if we are using the merging callback ?
I mean, word allow some other formatting options and I just wanted to know if overiding of all word option is the only solution ?

Regards.
Hi Edwige,

Thanks for your inquiry. Generally, Aspose.Words' mail merge engine supports formatting switches specified in merge fields. However, please note that the FieldMergingArgs.Text property inserts the text in document as it is without applying the switches. Switches only work when constructing field's result during normal mail merge process. So, to get the desired result, you will need to build the same "string" manually and pass it to FieldMergingArgs.Text property. Please let us know if we can be of any further assistance.

Best regards,

Hello,


Ok, thanks for your reply.

Regards.