Hi
Thanks for your request. Only paragraphs that contain one empty mergefield will be removed. If you need to remove paragraphs during mail merge you can try using MergeField event handler. Please see the following link to learn more: https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
Also see the following code example.
class HandleMergeFieldRemoveEmptyLine implements MergeFieldEventHandler
{
public void mergeField(Object sender, MergeFieldEventArgs e) throws Exception
{
// Remove paragraph if value of mergefield is null or empty string
if(e.getFieldValue() == null || e.getFieldValue() == "")
{
CompositeNode parent = (CompositeNode)e.getField().getEnd().getAncestor(NodeType.PARAGRAPH);
if(parent!=null)
{
// If there is no more fields in the paragraph
if(parent.getChildNodes(NodeType.FIELD_START, true).getCount()==1)
parent.remove();
}
}
}
}
Thanks a lot, the code helped. But a problem was that in a mailmerge run no node could be removed. So I collected all matching nodes and removed them after the mailmerge run.
If blank should be removed, following code does it in the eventhandler: