MailMergeCleanupOptions.RemoveUnusedRegions removes entire paragraph

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");
        }
    }
}

}

Hi Antti,

Thanks for your inquiry. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of any correction, we have logged this problem in our issue tracking system as WORDSNET-14829. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Antti,

In addition to my previous reply, can you please run the following code and see if this solution is acceptable for you?

Document doc = new Document(MyDir + @"removeregions.docx");
doc.MailMerge.UseWholeParagraphAsRegion = false;
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(MyDir + @"17.1.0.docx");

Best regards,

Thanks for the fast reply!

Yes indeed by using:

doc.MailMerge.UseWholeParagraphAsRegion = false;

Resolved the issue! So maybe WORDSNET-14829 is a non-issue and more of an ignorance by my part?

Hi Antti,

Thanks for your feedback. We have closed WORDSNET-14829 and marked it as “Not a Bug”. You can use MailMerge.UseWholeParagraphAsRegion property to get or set a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region.

Best regards,