Add mergeformat to mergefields

Hello,

I want to generate a Word document and add some mergefields to it.
When I manually add merge fields via Word to the document, I can select ‘Preserve formatting during updates’, so the existing formatting will be preserved.

Is it possible to add the ‘MERGEFORMAT’ when a document is created via code?

Thank you in advance!

Kind regards,
Joeri

Hi Joeri,

Yes, try this:

new Field(document, FieldType.MergeField, "ContractID \\* MERGEFORMAT", "«ContractID»")

Does this solve your issue?

Also, just as an FYI, note that GemBox.Document’s mail merge process will preserve the formatting even when the MERGEFIELD doesn’t have that switch.

Regards,
Mario

Hello Mario,

Thank you for the reply. It is working with the correct formatting.

Regards,
Joeri