Access to all field code components

Hi,

Is there any way through the API to access all parts of a field code? So if in my document template I define:

{MERGEFIELD “TestDate” \b pre \f post * MERGEFORMAT}

is there any way to see all three components - the name, the prefix text and the postfix text?


The reason I ask is, imagine I could write something like:

{MERGEFIELD “TestDate” \b pre \f post \udf foo \udf bar * MERGEFORMAT}

where udf = user-defined field/format/function. This would allow the users to embed additional formatting information into the merge fields. The users would be given a list of what the valid instructions are and the IT department can provide a generic document generation service which handles all the valid instructions rather than having to create specific C# code to handle the different document templates.

TIA,
Phil

“\udf something” will not work as MS Word will delete merge field options it does not understand whenever the field is edited or updated. I’m not 100% sure on this, but I think I tried this before.

What sort of formatting information are you talking about? For numbers and dates? There are standard @ and # flags available in MS Word that allow specifying date and number formats and Aspose.Word does not them yet, but they will be supported soon.

If you are looking for more than just date and number formatting, please provide more details and we will try to suggest a suitable solution.

Hi Roman,

Within MergeFields, Aspose.Word supports @ and # formatting commands for date and curriencies when using Output.MailMerge.ExecuteWithRegions(DataSet).

Are the same commands now supported when using DocumentBuilder.MoveToMergeField(FieldName).

The reason behind this is we use both classes in our Document Production Service, and we need to be able to offer this functionality to our users when they are creating word templates.

DocumentBuilder is used to output non repeating information, and MailMerge is used to output repeating information.

We were also wondering if you are going to offer functionality to embed additional formatting information into the MergeFields, such as what was requested in the above forum posts.

We would like to offer the users who create the templates, MergeField functionality where certain criteria is met.

Such as deleting, ignoring, or replacing values.
e.g. If value = “Orange” then make Value = "Blue"

Thanks,
Rich.

@ and # do not apply when using DocumentBuilder.MoveToMergeField because it just moves the cursor to a specific position and allows you to insert various content, images, tables, formatting. I’m not sure how formatting flags can be applied in this case. Also, keep in mind that DocumentBuilder.MoveToMergeField moves the cursor to a merge field AND deletes the merge field.

We have not done any work on extending merge fields and reporting functionality yet, although its in our plans. I also think we will eventually support MS Word conditional fields IF etc. We are currently researching parsing engines for this.