Applying Custom Formatting to Fields

How to Apply Custom Formatting to Field Result

Aspose.Words provides API for custom formatting of field’s result. You can implement IFieldResultFormatter interface to control how the field result is formatted. You can apply numeric format switch, i.e. # “#.##”, date/time format switch, i.e. @ “dd.MM.yyyy”, and number format switch, i.e. * Ordinal. Following code example shows how to apply custom formatting for field’s result.

How to evaluate IF condition

If you want to evaluate IF condition after mail merge, you can use FieldIf.EvaluateCondition method that immediately returns the result of expression’s evaluation. Below code example shows how to use this method. 

How to Apply Custom Formatting to Time Field

By default Aspose.Words updates TIME field with current culture short time format. We figured out that there is a difference between MS Word formatting and .NET/Windows formatting and also between different .NET Framework versions. If you want to format the Time field according to your requirement, you can achieve this by implementing IFieldUpdateCultureProvider interface. Below code example shows how to apply custom formatting to Time field.

Field Display Result

Aspose.Words provides a property to obtain the field’s result for fields that do not have a field separator node. We call this “fake result” or display result; MS Word displays it in the document by calculating the field’s value on the fly, but there is no such value in the document model.

The following code example shows the usage of Filed.DisplayResult property.