Page 1 of 1

Mergefield with data lists and MERGESEQ supported?

PostPosted: Thu Jul 10, 2014 1:44 am
by dtoch
I have the scenario where I want to perform a MergeField with the following input data records:

CITY EMPLOYEE
BRUSSELS JOHN
LONDON PETER
ESSEX PAUL

and where the input docx contains the following MergeField construct:

{ If { MERGESEQ } = "1" "{ MERGEFIELD CITY }¶
" ""}{ SET Place1 { MERGEFIELD CITY }}¶
{ If { Place2 } <> { Place1 }"¶
----------------------------Page Break--------------------------------
{ MERGEFIELD CITY }¶

{ MERGEFIELD EMPLOYEE } }{ SET Place2 { MERGEFIELD CITY }}¶

So I want to have only one resulting output document with the data of the 3 records merged in it (each separated by a Page Break).

The basic MergeField example given on the Docx4j site works perfectly and can be used for the above input data records to create one separate document per record, but I don't seem to figure out how to use it to create only one resulting document.

Is the scenario that I'm trying to perform possible with Docx4j or doesn't it support that (yet)?

Re: Mergefield with data lists and MERGESEQ supported?

PostPosted: Thu Jul 10, 2014 7:28 am
by jason
I'm afraid docx4j can't evaluate IF, MERGESEQ, or SET.

You can place all the results in a single docx, using getConsolidatedResultCrude in MailMerger class.

You can do conditional content via content control databinding. And you can use org.docx4j.model.datastorage.migration.FromMergeFields to migrate from MERGEFIELD to content controls.