Adding bold to a merge field

Hi,
I was wondering it it was possible to achieve the following?
I have a merge field called <MergeField>.
I would like it to contain the following text:
The cat sat on the mat.
As you can see, I only want to make part of the text bold. can this be achieved with Words and vb.net?
Thanks in advance

Hi Joe,

Thanks for your inquiry. First of all, please note that Aspose.Words is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following articles for more information on DOM:
https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://docs.aspose.com/words/net/logical-levels-of-nodes-in-a-document/
https://docs.aspose.com/words/net/document-builder-overview/
https://reference.aspose.com/words/net/aspose.words/run/

Please use IFieldMergingCallback Interface in your code to achieve your requirement as shown below:

Dim doc As New Document("D:\in.docx")
doc.MailMerge.FieldMergingCallback = New HandleMergeField()
doc.MailMerge.Execute(New String() {"FieldName"}, New Object() {"Field Value"})
doc.Save("D:\AsposeOut.doc")
Private Class HandleMergeField
    Implements IFieldMergingCallback
    Private mBuilder As DocumentBuilder
    ''' 
    ''' This is called when merge field is actually merged with data in the document.
    ''' 
    Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
        ' All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'.
        If mBuilder Is Nothing Then
            mBuilder = New DocumentBuilder(e.Document)
        End If
        If e.FieldName.Equals("FieldName") Then
            'Here you can modify code according to your requirements.
            mBuilder.MoveToMergeField(e.FieldName)
            Dim run As New Run(e.Document)
            run.Text = "New text with different font style"
            Dim font As Aspose.Words.Font = run.Font
            font.Size = 12
            font.Bold = True
            font.Color = System.Drawing.Color.Red
            font.Name = "Verdana"
            mBuilder.InsertNode(run)
        End If
    End Sub
    Private Sub ImageFieldMerging(ByVal e As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging
        ' Do nothing.
    End Sub
End Class