We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Feature Request for Mail Merge / Mail Merge Group and XHTML

Hi,

currently i'm using some random string in mail merge to replace xhtml parts later on with xhtml from our database.  This is something like this:


Dim textDictionary As New Dictionary(Of String, String)
...
Dim uid = TokenGenerator.NewGuid.ToString

While textDictionary.ContainsKey(uid)
    uid = TokenGenerator.NewGuid.ToString
End While

textDictionary.Add(uid, textToAdd)
temp.Text = "<<TempHTML_" & uid & ">>" 'temp is one element of my model as list

 Dim dataTable = New MailMergeDataTable("MainCategory", model)


doc.Open(currentFilePath, FormatType.Automatic)
doc.MailMerge.RemoveEmptyGroup = True
doc.MailMerge.RemoveEmptyParagraphs = True
doc.MailMerge.ExecuteNestedGroup(dataTable)


For Each entry In textDictionary
    Dim selection As TextSelection = doc.Find(New System.Text.RegularExpressions.Regex("<<TempHTML_" & entry.Key & ">>"))
    If Not IsNothing(selection) Then
        Dim OwnerParagraph As WParagraph = selection.GetAsOneRange().OwnerParagraph
        If TypeOf OwnerParagraph.OwnerTextBody Is WTextBody Then
            Dim tb As WTextBody = TryCast(OwnerParagraph.OwnerTextBody, WTextBody)
            OwnerParagraph.ChildEntities.Clear()
            OwnerParagraph.AppendHTML(entry.Key)
        End If
    End If
Next


Is there some way to get my xhtml directly into mail merge? Is there a chance to get some dircet function for inserting xhtml in mail merge?

Kinf regards,
lc

1 Reply

SK Sathish K Syncfusion Team September 30, 2015 03:37 PM UTC

Hi Lc,

Thank you for contacting Syncfusion support.

Currently DocIO doesn’t provide support for html formatted string in mail merge. Alternatively you shall achieve this through mail merge event handler during mail merge. Kindly use the following code example to achieve the same.

Code example:
document.MailMerge.MergeField += MailMerge_MergeField

document.MailMerge.ExecuteNestedGroup(dataTable)

Event Handler code:
Private Sub MailMerge_MergeField(sender As Object, args As MergeFieldEventArgs)

If args.FieldName = "HTMLFieldName" Then

'Gets the Html String

Dim HTMLtext As String = TryCast(args.FieldValue, String)

'Gets the index of the owner paragraph of the current merge field

Dim paraIndex As Integer = args.CurrentMergeField.OwnerParagraph.OwnerTextBody.ChildEntities.IndexOf(args.CurrentMergeField.OwnerParagraph)

'Gets the index of the current merge field

Dim paraItemIndex As Integer = args.CurrentMergeField.OwnerParagraph.ChildEntities.IndexOf(args.CurrentMergeField)

'Inserts the html string at the specified location               

 args.CurrentMergeField.OwnerParagraph.OwnerTextBody.InsertXHTML(HTMLtext, paraIndex, paraItemIndex)

'Clears the text

args.Text = String.Empty

End If
End Sub

Regards,
Sathish


Loader.
Live Chat Icon For mobile
Up arrow icon