Changing case of mail merge fields

8 posts, 0 answers
  1. Troy
    Troy avatar
    1 posts
    Member since:
    Mar 2015

    Posted 07 May 2015 Link to this post

    Hi,

      There are switches you can use in Word to make the value of a mail merge field change case.  Ex. \* FirstCap, \* Upper, \* lower.  These don't seem to work correctly in the RichTextBox.  I'm adding the fields in code and the values display but the formatting isn't correct.  I've taken a template I made in Word and tried that which works correctly in Word but doesn't in the Telerik control so I'm not sure it is my code that is the issue.

      Any help would be appreciated.

          Troy

  2. Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 12 May 2015 Link to this post

    Hello,

    I am pasting the answer of this question in case somebody else needs it:

    "Currently these switches are not supported in the RadRichTextBox. We have already logged this request and you could vote and subscribe to the public item in the feedback portal in order to receive updates about status changes on it. 

    In order to achieve your goal you could implement a custom MergeField. I am attaching a simple project, which demonstrates how such field could be implemented to support the "\* upper" switch
    ."

    Regards,
    Tanya
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Brian Stanek
    Brian Stanek avatar
    15 posts
    Member since:
    Jan 2008

    Posted 07 Dec 2015 in reply to Tanya Link to this post

    Is there a way I can make the formatting code {EQ \a ({MERGEFIELD Names})} to work in RadRichTextBox to display names separated by commas in multiple lines? I have verified that this works in MS Word. Thanks.

  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 08 Dec 2015 Link to this post

    Hello Brian,

    EQ field is not supported out of the box, moreover it seems kind of deprecated now as it's not included in the MS Word fields help article nor in the last editions of the Office Open XML (sure Word still supports it for backward compatibility).

    It should be somewhat tricky, but possible, to implement the EQ functionality you want as a custom field. You can use the tutorial in the Custom Field help article that Tanya linked. Other resource that might be helpful is the Custom Field SDK demo in our xaml-sdk repo on GitHub.

    Basically you should create a FieldProperty (and a corresponding CLR property) for each of the switches. Then, based on the values of the switches, you can create proper DocumentFragment by overriding the GetResultFragment method. 

    Regards,
    Boby
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Brian Stanek
    Brian Stanek avatar
    15 posts
    Member since:
    Jan 2008

    Posted 09 Dec 2015 in reply to Boby Link to this post

    Hi Boby,

    Thanks for your prompt reply. Using Custom Field for mail merge, it works great in the RadRichTextBox. However, I am actually doing mail merge programmatically using RadFlowDocument.MailMerge() method. Is there a way to handle the custom mail merge fields programmatically?

    Cheers,

    Brian

     

  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 10 Dec 2015 Link to this post

    Hi Brian ,

    I am confused. You mentioned RadFlowDocument.MailMerge, which is the document class from WordsProcessing (located in Telerik.Windows.Documents.Flow). On contrary, RadRichTextBox uses RadDocument (located in Telerik.Windows.Documents).

    RadDocument supports the concept for custom fields, and my suggestions was for its API. RadWordsProcessing API currently doesn't allow updating of custom fields, though you can insert them in the document and they are preserved on import/export to DOCX (of course you can manually "update" them by replacing their result fragment directly in the document model).

    Could you clarify what is your scenario and which components are you using?

    Regards,
    Boby
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Brian Stanek
    Brian Stanek avatar
    15 posts
    Member since:
    Jan 2008

    Posted 10 Dec 2015 in reply to Boby Link to this post

    Hi Boby,

    When I manually update the merge fields using result fragment, is there a way to add a carriage return/line break? I am using RadFlowDocumentEditor to modify a RadFlowDocument progammatically where I need to insert another document, add header and footer and perform mail merge. And I also need to support the mail merge fields to display data in multiple lines. 

    Thanks.

  9. Boby
    Admin
    Boby avatar
    595 posts

    Posted 11 Dec 2015 Link to this post

    Hi Brian,

    First I want to mention that multiline field result should be supported out of the box, however the current implementation has bug in it, namely this one:
    Mail merge doesn't respect new lines from mail merge source

    If you are manually replacing merge fields with their result, RadDocumentEditor won't help, as it's purpose is to do more high-level interactions. Instead you could use directly the document model to remove the field inlines and replace them with the result. For example, the following will remove the merge-field-associated inlines for the first merge field.

    // this is just an example on how to get the first merge field.
    var fieldStart = document.EnumerateChildrenOfType<FieldCharacter>()
        .Where(fc => fc.FieldCharacterType == FieldCharacterType.Start && fc.FieldInfo.Field is MergeField)
        .First();
     
    var fieldEnd = fieldStart.FieldInfo.End;
     
    var parentParagraph = fieldStart.Paragraph;
     
    List<InlineBase> inlinesToRemove = new List<InlineBase>();
     
    bool found = false;
     
    foreach (var inline in parentParagraph.Inlines)
    {
        if (!found && inline == fieldStart)
        {
            found = true;
        }
     
        if (found)
        {
            inlinesToRemove.Add(inline);
     
            if (inline == fieldEnd)
            {
                break;
            }
        }
    }
     
    foreach (var inline in inlinesToRemove)
    {
        parentParagraph.Inlines.Remove(inline);
    }

    If you want to continue our conversation further, I would suggest you to open a dedicated support thread for RadWordsProcessing or continue in the RadWordsProcessing forum, as this forum is dedicated to RadRichTextBox.

    Regards,
    Boby
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready