Mailmerge features

Received : 2007/11/14 19:06:15
Message : Hello,

I am wondering if the following are possible in Aspose words?

When performing mail merges I need to do the following:

I have an optional field that needs the following formatting:
“Heading - the remaining text…” I need the heading to be in Bold and the remainder of the paragraph to be normal text. If there is no text for this heading, then it should not appear at all.

Changing the color of the font based on the data:
I would like to following to appear in a single merge field depending on the response

Good(green) or Bad(red) or Borderline(orange). Is it possible to change the color of the mergefield text in the VB code behind?

Finally, I have two rows in the middle of a table that I do not want to appear if some conditions are not met. Is there any way to only include these two rows if the conditions are met?

This message was posted using Aspose.Live 2 Forum

Hi
Thanks for your interest in Aspose products. I think that you can try to use MergeField event to achieve this. For example see the following code.

Sub Main()
Dim doc As Document = New Document("in.doc")
AddHandler doc.MailMerge.MergeField, AddressOf HandleMerge
Dim names As String() = {"Field1"}
Dim values As String() = {"Bold text |Red text |Regular text"}
' Execute mail merge.
doc.MailMerge.Execute(names, values)
doc.Save("out.doc")
End Sub
Private Sub HandleMerge(ByVal sender As Object, ByVal e As MergeFieldEventArgs)
If e.FieldName = "Field1" Then
Dim builder As DocumentBuilder = New DocumentBuilder(e.Document)
builder.MoveToMergeField(e.FieldName)
Dim arr As String() = e.FieldValue.ToString().Split("|")
Dim i As Integer = 0
For i = 0 To arr.Length - 1
If i = 0 Then
builder.PushFont()
builder.Font.Bold = True
builder.Write(arr(i))
builder.PopFont()
ElseIf i = 1 Then
builder.PushFont()
builder.Font.Color = System.Drawing.Color.Red
builder.Write(arr(i))
builder.PopFont()
Else
builder.PushFont()
builder.Font.ClearFormatting()
builder.Write(arr(i))
builder.PopFont()
End If
Next
End If
End Sub

Also see the following links.
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
I hope that this will help you.
Best regards.