Free Support Forum - aspose.com

RemoveEmptyParagraphs for TableStart / TableEnd

Hi, Is it possible to have the RemoveEmptyParagraphs flag handle removing empty lines that contain nothing but a <> or <>?

For other merge fields, will it support removing blank lines caused by NULL values as well as blanks?

Thanks.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you can use MergeField event handler to achieve this. For example see the following code and attached documents.

public void Test253()

{

//Create some datasource

DataTable myTable = new DataTable("myTable");

myTable.Columns.Add("field1");

myTable.Columns.Add("field2");

myTable.Columns.Add("field3");

for (int i = 0; i < 10; i++)

{

myTable.Rows.Add(new object[] { i.ToString(), "Some data" + i.ToString(), "Some text" + i.ToString() });

}

//perform mailmerge

Document doc = new Document(@"Test253\in.doc");

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_253);

doc.MailMerge.ExecuteWithRegions(myTable);

doc.Save(@"Test253\out.doc");

}

void MailMerge_MergeField_253(object sender, MergeFieldEventArgs e)

{

if (e.FieldName == "field1")

{

Table parentTable = (e.Field.Start.GetAncestor(NodeType.Table) as Table);

//Remove empty paragraphs before and after table

parentTable.NextSibling.Remove();

parentTable.PreviousSibling.Remove();

}

}

Hope this helps.

Best regards.