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
9 Answers, 1 is accepted
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.

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.
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

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
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

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.
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

Hi, I have an existing Word document set up for mail merge. In other words, merge fields are already in the document. How do I mail merge to this kind of document. I am able to load the existing document into a RadFlowDocument, and then call MailMerge(data), but the mail merge does not occur.
private static void TestMailMerge()
{
List<
MailMergeRecord
> mailMergeDataSource = new List<
MailMergeRecord
>()
{
new MailMergeRecord()
{
Test = "test-string",
SalesTaxLicenseNumber = "stnumbertest"
},
new MailMergeRecord()
{
Test = "test-string-2",
SalesTaxLicenseNumber = "stnumbertest2"
},
};
RadFlowDocument document;
var fileFormatProvider = new DocxFormatProvider();
string fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TrashMaybe\\Waiver-Denied 4-10.docx");
using (FileStream input = new FileStream(fileName, FileMode.Open))
{
document = fileFormatProvider.Import(input);
}
document.MailMerge(mailMergeDataSource);
document.UpdateFields();
using (Stream output = new FileStream("C:\\temp\\output.docx", FileMode.OpenOrCreate))
{
fileFormatProvider.Export(document, output);
}
}
RadFlowDocument.MailMerge(*) method returns a new instance of RadFlowDocument, instead of modifying the template.
Also this is the forum for RadRichTextBox, and you are using RadFlowDocument and its mail merge functionality, which is part of RadWordsProcessing. If you want to use the RadRichTextBox-related classes (which has more features available, but could be slower), you should instead use RadDocument and its mail merge capabilities.
Regards,
Boby
Progress Telerik