We have a template (template_with_sections.dot) that includes a MERGEFIELD, an IF statement and a section break such that the two sections have different page settings. The IF then controls whether to insert the section break. The MERGEFIELD is used in the condition of the IF.
The template_with_sections.dot has the following combination of IF, MERGEFIELD and sections.
{ IF { MERGEFIELD First_Page_Orientation} = "L" "Landscape SECTION BREAK" ""}
Portrait
The template should behave in the following way. If being merged with data whose First_Page_Orientation is ‘L’ then the first page should appear in landscape with the text “Landscape” and all remain pages should be Portrait. If First_Page_Orientation is any other letter, say ‘P’ then we expect all pages to be portrait with text “Portrait”.
We previously would perform the mail merge using word directly via its api in a visual basic script. When executing the mail merge via this script the produced document ended up as described above and shown in the attachment expected_output.docx.
When run via Aspose.Words using the following code (this is not the actual code but in terms of the aspose usage it is the same, the customDataSource basically holds the contents of example_data.txt)
final Document template = new Document( new FileInputStream("template_with_sections.dot") );
template.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS |
MaiMergeCleanupOptions.REMOVE_UNUSED_REGIONS |
MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
template.getMailMerge().execute(customDataSource);
final FileOutputStream outputStream = new
FileOutputStream(new File(actual_output.doc));
template.save( outputStream, SaveFormat.DOC);
When using Aspose.Words to merge the same template with a data file that contains a First_Page_Orientation of L then it produces a document as expected (first page should appear in landscape with the text “Landscape” and all remain pages should be Protrait). However, when merging with a data file that contains P for the First_Page_Orientation it produces a document like actual_output.doc (a document where the first page is landscape but has the text Portrait).
How can I get Aspose to have the same behaviour as the old vbs script manipulating word directly?
I hope this makes sense and any advice would be much appreciated.
Note: We are using Aspose.Words 13.8.