Empty bullet points are not getting removed from document after upgrading to Aspose.words 23.1

Hi Team,

Empty bullet points are not getting removed from document after upgrading to Aspose.words 23.1.

There is a merge field named “problem” in the given templateTemplate.png (10.1 KB)
. If the value in the merge field getting as null or empty, an empty bullet point is getting displayed in the actual output fileOutput.PNG (6.0 KB)
.

But the empty bullet point was not getting displayed with Aspose.Words 11.8 version. This issue started after upgrading to Aspose.words 23.1.

If the value in the merge field is null or empty, the bullet point should not be displayed in the output document. Do we have any solution for this issue?

@Febinbabu You should specify MailMergeCleanupOptions.RemoveEmptyParagraphs option to get the expected result.

Hi Alexy,

Tried with this code

. It doesn’t work. Could you please explain how to implement it.

@Febinbabu You should use the following code:

Document doc = new Document("in.docx");

// Specify cleanup options
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;

// execute mail merge
// ......

IF the problem still persist, please attach your sample input document here for testing. We will check the issue and provide you more information.

Hi Alexy,

I am attaching the sample document here.
Sample.zip (8.6 KB)

There is a merge field named “problem” in the document. we are getting the merge field value from a stored procedure. If the value is null or empty, don’t need to display the empty bullet point in the generated pdf document. The bullet point should be removed.

In Aspose.words 11.8 version, the bullet point also was getting removed by default if the merge field value is null or empty. After upgraded to 23.1 started facing this issue.

Can u please check the document and provide me the code.
I tried in my solution with this code as you suggested. It is not working.
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;

@Febinbabu Cleanup options works fine on my side. please try using the following code:

Document doc = new Document(@"C:\Temp\in.doc");
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.Execute(new string[] { "problem" }, new object[] { "" });
doc.Save(@"C:\Temp\out.docx");

This code works fine for me. Thanks.

In our case, we are using doc.MailMerge.ExecuteWithRegions(DS);
here the RemoveEmptyParagraphs is not working.

In our real scenario, getting data set with multiple data tables in it.

Proving demo code and template below. can u pls look into this.
Template.zip (7.9 KB)

DataTable workTable = new DataTable("Customers");
DataSet ds = new DataSet(); 
workTable.Columns.Add("problem", typeof(String));
DataRow workRow = workTable.NewRow();
workRow["problem"] = "Test test test";
workTable.Rows.Add(workRow);
ds.Tables.Add(workTable);
Document doc = new Document(@"C:\Test\Template.doc");
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.ExecuteWithRegions(ds );
doc.Save(@"C:\Test\Out.pdf");

@Febinbabu The region in your template is in table. What is the purpose of wrapping region that encloses only one paragraph in the table? In this case the empty paragraphs are properly removed, but table cell cannot be absolutely empty, it must contain at least one paragraph. So Aspose.Words adds an empty paragraph that produces a gap. I would suggest to remove the wrapping tables where they are not required from the template.

Hi Alexy,
We are getting the value for the merge filed named “problem” from the database table in the real case. some times it may contains multiple records. If it returns 10 values, it should be displayed in 10 rows with bullet points in each of the data in the document.
If the value is null or empty, it should not display even a single bullet point.

@Febinbabu Thank you for additional information. Yes, the requirements are clear. To achieve this I would suggest to remove the table that wraps the list item in your template and use a single paragraph as a region. For example see the attached template code and output:

DataTable dt = new DataTable("Data");
dt.Columns.Add("Item");
dt.Rows.Add("First");
dt.Rows.Add("Second");
dt.Rows.Add("");
dt.Rows.Add("Third");
dt.Rows.Add(new object[] { null});
dt.Rows.Add("Fourth");

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.ExecuteWithRegions(dt);
doc.Save(@"C:\Temp\out.docx");

in.docx (13.8 KB)
out.docx (11.1 KB)