We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

RemoveEmptyParagraphs Not Behaving as Expected

We have a template that uses fixed font data to create a simple table. It does this by using the following merge tag sequence:

{ MERGEFIELD LineData }{ NEXTIF { MERGEFIELD LineData} <> ""}
{ MERGEFIELD LineData }{ NEXTIF { MERGEFIELD LineData} <> ""}
{ MERGEFIELD LineData }{ NEXTIF { MERGEFIELD LineData} <> ""}
<... repeat as may times as necessary>

The document will keep merging in the next record until it encounters an empty line. When that occurs, all remaining LineData fields get set to a blank. Then MS Word then removes all the remaining blank lines in that document.

However, Apose.Words behaves differently. The data is merged exactly as expected. However, that blank lines that are inserted are not removed, even if the RemoveEmptyParagraphs clean up option is set on. Empty paragraphs above this set of mergefields are removed as expected when the RemoveEmptyParagraphs clean up option is set on.

I have a attached a test case document to reproduced this behavior. C# code that generates the merged doc:


    class Program
    {
        static void Main(string[] args)
        {

            License lic = new License();

            lic.SetLicense("Aspose.Words.lic");

            Document doc = new Document("Test mail merge document.doc");


            using (DataTable dt = new DataTable())
            {
                dt.Columns.Add("Field1",typeof(string));
                dt.Columns.Add("Field2",typeof(string));
                dt.Columns.Add("Field3", typeof(string));
                dt.Columns.Add("LineData", typeof(string));

                for (int i = 0; i < 10; i++)
                {
                    DataRow row = dt.NewRow();

                    row["Field1"] = "Data for Field1";
                    row["Field2"] = ""; //"Data for Field2";
                    row["Field3"] = "Data for Field3";
                    row["LineData"] = String.Format("{0,8:00000000}   XXXXXX", i);
                    
                    dt.Rows.Add(row);

                    row = dt.NewRow();

                    if (i % 2 == 1)  // two lines per document
                    {
                        row["Field1"] = "Data for Field1";
                        row["Field2"] = "";  // "Data for Field2";
                        row["Field3"] = "Data for Field3";
                        row["LineData"] = "";

                        dt.Rows.Add(row);
                    }
                   
                }

                DataRow row2 = dt.NewRow();

                row2["Field1"] = "Data for Field1";
                row2["Field2"] = ""; // "Data for Field2";
                row2["Field3"] = "Data for Field3";
                row2["LineData"] = "";

                dt.Rows.Add(row2);

                doc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs;
                doc.MailMerge.Execute(dt);
            }

            doc.Save("MergedDoc.pdf", SaveFormat.Pdf);
            doc.Save("MergedDoc.doc", SaveFormat.Doc);

        }
    }

Is there any way to work around this behavior ?

Regards,
Kevin Jones

Hi Kevin,


Thanks for your inquiry. I am checking with this scenario and will get back to you soon.

Best regards,
Hi Kevin,

Thank you for being patient. I tested the scenario and have managed to reproduce the same problem on my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-8451. Our development 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,

The issues you have found earlier (filed as WORDSNET-8451) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.