Spell checking, MailMerge and UserDictionaries

Today, we received an interesting request from a TX Text Control user. The requirement was straightforward:

A template should be prepared by merging data using the MailMerge component. The resulting document has to be presented to the end-user to allow final changes or to add additional text.

But the merged text, that comes directly from the data source, shouldn't be marked as incorrect by TX Spell .NET, even if the field text is misspelled. This requirement can be easily solved using a UserDictionary. TX Spell .NET can be used with an umlimited number of UserDictionaries thus allows you to use them for other purposes as well.

In this case, we would like to store all words from the mail merge process in a separate UserDictionary. This can be achieved in the FieldMerged event of the MailMerge class:

TXTextControl.Proofing.UserDictionary user =
    new TXTextControl.Proofing.UserDictionary();

private void mailMerge1_FieldMerged(object sender,
    TXTextControl.DocumentServer.MailMerge.FieldMergedEventArgs e)
{
    MergeField field = e.MailMergeFieldAdapter as MergeField;

    foreach (string word in field.Text.Split(' '))
    {
        user.AddWord(word);
    }
}

These words are now ignored automatically and you can remove the temporary UserDictionary when merging the next document.