Hi!
I have recently noticed this strange behaviour when using MailMerge.ExecuteWithRegions() -method. I am using Aspose.Words version 16.10.1.0
I have this text in a docx document:
why does this text dissappear? Is this whole paragraph part of the same region with the tablestart mergefield? {{ #foreach things}}{{thing}}{{/foreach things}}
on another paragraph text is preserved
If I set the “MailMergeCleanupOptions.RemoveUnusedRegions” -flag then after executing ExecuteWithRegions() that whole first paragraph is removed from the resulting document. What I wish to achieve is that only the part of the document within the foreach loop would be removed and other text in the paragraph be preserved.
attached the template. Code below:
using Aspose.Words.MailMerging;
using System.Data;
using System.IO;
namespace asposetest
{
class Program
{
private static Aspose.Words.License _wordsLicense;
static Program()
{
//Set the license
_wordsLicense = new Aspose.Words.License();
_wordsLicense.SetLicense(new MemoryStream(
File.ReadAllBytes(@"C:\Aspose\Aspose.Words.lic")));
}
static void Main(string[] args)
{
using (var stream = new MemoryStream(
File.ReadAllBytes(@"C:\Temp\removeregions.docx")))
{
var doc = new Aspose.Words.Document(stream);
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.CleanupOptions =
MailMergeCleanupOptions.RemoveUnusedFields
| MailMergeCleanupOptions.RemoveUnusedRegions //why does this remove
//the entire paragraph?
| MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.ExecuteWithRegions(new DataTable());
doc.Save(@"C:\Temp\removeregions_out.docx");
}
}
}
}