Hi there,
First, a hint which might be useful to future users.
I open a document template, and clone that in order to merge multiple results.
Clone, doesn’t include the mailmerge cleanupoptions, and they must be set manually afterwards.:
ie.:
TemplateDocument = new Aspose.Words.Document(“template.dot”);
TemplateDocument.MailMerge.UseNonMergeFields = true;
TemplateDocument.MailMerge.CleanupOptions =
MailMergeCleanupOptions.RemoveStaticFields |
MailMergeCleanupOptions.RemoveContainingFields |
MailMergeCleanupOptions.RemoveEmptyParagraphs |
MailMergeCleanupOptions.RemoveUnusedFields |
MailMergeCleanupOptions.RemoveUnusedRegions;
object[] FieldNames, FieldValues;
/*
* Parse data into object arrays here…
*/
Document merge_document = TemplateDocument.Clone();
// Clone doesn’t include these settings…
merge_document.MailMerge.UseNonMergeFields = TemplateDocument.MailMerge.UseNonMergeFields;
merge_document.MailMerge.CleanupOptions = TemplateDocument.MailMerge.CleanupOptions;
// Perform merge.
merge_document.MailMerge.Execute(FieldNames, FieldValues);
Now for the trouble…
The template file includes a mergefield, that explicitly creates an empty newline.
This newline is removed when using Aspose to perform the mailmerge, and using
MailMergeCleanupOptions.RemoveEmptyParagraphs
The MergeCode would be something like this:
{ IF { MERGEFIELD “field1” } <> 0 “\r\nInsert newline above this text: { MERGEFIELD “field2” }” “” }
but look at the attached files, and let me know what you think.
Is there a possible workaround, or do you need to fix this internally?
Thank you,
Jens.