Hi
We are attempting to merge a template that contains if statements and merge fields which may or may not be merged with data.
For example
{ IF { MERGEFIELD Sex } = “M” "
{ MERGEFIELD Address_Line_1 }
{ MERGEFIELD Address_Line_2 }
{ MERGEFIELD Address_Line_3 }
" “” }
Is then merged with the following data
Sex='M’
Address_Line_1=‘Yellow Brick Road’
Address_Line_2=’'
Address_Line_3='Somewhere over the rainbow’
We want the following produced.
Yellow Brick Road
Somewhere over the rainbow
Notice the removal of the Address_Line_2 from the produced document as well as the IF statement being removed.
Currently we get.
Yellow Brick Road
Somewhere over the rainbow
We are using Aspose.Words 14.2.0 and calling it in the folllowing manner.
template.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
template.getMailMerge().execute(customDataSource);
In our customDataSource the getValue method is currently implemented as follows
public boolean getValue(final String fieldName, final Object[] fieldValue)
{
final String value = this.data.get(this.recordIndex).getValue(fieldName);
fieldValue[0] = value;
return null != value;
}
Any help would be appreciated.
Regards
<!–[if supportFields]> IF MERGEFIELD Sex = “M” "
MERGEFIELD Address_Line_1
MERGEFIELD Address_Line_2
MERGEFIELD Address_Line_3
MERGEFIELD Address_Line_4
MERGEFIELD Address_Line_5
" ""