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, Aspose.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