We are using the Aspose.Words mail merge methods (MailMerge.Execute
/ MailMerge.ExecuteWithRegions
) to merge data and repeating rows of data into a document from an XML file data source.
For example:
MailMerge.Execute
for:
{ MERGEFIELD INCLUDE_TABLE }
MailMerge.ExecuteWithRegions for:
{ MERGEFIELD TableStart:T1 }--{ MERGEFIELD CODE }--{ MERGEFIELD TableEnd:T1 }
{ MERGEFIELD TableStart:T2 }--{ MERGEFIELD CODE }--{ MERGEFIELD TableEnd:T2 }
However, what we would like to do is conditionally merge data from one of the two different tables (either table ‘T1’ or table ‘T2’) depending on a basic Word IF condition. For example, the equivalent of the following pseudo code:
{ IF {MERGEFIELD INCLUDE_TABLE} = "1" "(true = merge rows from T1)" "false = merge rows from T2"}
The example code being:
{ IF { MERGEFIELD INCLUDE_TABLE } = "1" "{ MERGEFIELD TableStart:T1 }--{ MERGEFIELD CODE }--{ MERGEFIELD TableEnd:T1 }" "{ MERGEFIELD TableStart:T2 }--{ MERGEFIELD CODE }--{ MERGEFIELD TableEnd:T2 }" }
For an XML data source of:
<r>
<INCLUDE_TABLE>1</INCLUDE_TABLE>
<T1>
<CODE>T1.1</CODE>
</T1>
<T1>
<CODE>T1.2</CODE>
</T1>
<T2>
<CODE>T2.1</CODE>
</T2>
<T2>
<CODE>T2.2</CODE>
</T2>
</r>
The expected output would simply be:
–T1.1–
–T1.2–
For an XML data source of:
<r>
<INCLUDE_TABLE>2</INCLUDE_TABLE>
<T1>
<CODE>T1.1</CODE>
</T1>
<T1>
<CODE>T1.2</CODE>
</T1>
<T2>
<CODE>T2.1</CODE>
</T2>
<T2>
<CODE>T2.2</CODE>
</T2>
</r>
The expected output would simply be :
–T2.1–
–T2.2–
Using the above example, the merge generates the exception: “Mail merge regions ‘T1’ and ‘T2’ overlap. Two regions cannot start/end in the same paragraph or occupy the same table row.”
Is there are recommended way of doing this please – a specific configuration of the IF statement which would support this?
A second (and related) question. Please may we check the purpose for using the MailMergeCleanupOptions.RemoveContainingFields
option. We are using it for the merge (which may influence the main question above). Is the following correct?
For the example merge of:
{ IF {MERGEFIELD INCLUDE_TABLE} = "1" "true" "false"}
Where INCLUDE_TABLE = “1”
When ‘RemoveContainingFields’ is used in the merge, the result of the above will simply be ‘true’. The IF statement is removed from the merge document completely and cannot be returned using ALT-F9 to toggle the field code and value. Is this the purpose of the option?
Thanks in advance.