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

Free Support Forum - aspose.com

MailMerge.RemoveEmptyParagraphs fails if merge field name is followed by a space

We have amended our software to use the aspose dll rather than the WORD automation dll.

However, customers have lots (hundreds) of templates that that were previously working ok, but are now broken.

The situation occurs in the mailmerge. There are several lines of address, and empty lines must be removed so that it does not leave blank lines in the middle of the address. We are using MailMerge.RemoveEmptyParagraphs to try to achieve this functionality.

The problem appears when the merge field name is followed by an empty space.

e.g. <>space

The WORD automation dll will still remove the line, whereas the ASPOSE dll leaves a blank line.

I've attached an example for you.

Hello

Thanks for your request. MailMerge.RemoveEmptyParagrapgs works when the paragraph which contains MergeField is empty. In your template there is white space inside paragraph. Please try refactoring your document to avoid using white space.

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

Best regards,

Hi,

thanks for your quick response.

My problem is that we have many customers, each of these have hundreds of templates which may have this problem.

I realise that changing the template to remove whitespace works ok. However, it is impractical to open every template and remove the whitespace manually for every customer.

The WORD automation dll deals with the whitespace ok, and WORD also deals with the whitespace ok. So I think that ASPOSE should also deal with it.

Do you have any code we could use to make the ASPOSE solution work like WORD so that we could work around it ?

Or does this need to be a change request ?

Hi Robert,

Thanks for your inquiry.

Yes I think that the paragraphs should be removed even when there is a trailing space. I have logged this issue, it will be fixed sometime in the future. We will inform you as soon as this fix is ready.

In the mean time please try using this method below instead of RemoveEmptyParagraphs.

// List of fields in the document<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

string[] fieldNames = doc.MailMerge.GetFieldNames();

// A list to store the paragraphs that were merged with an empty value during mail merge

ArrayList mergedParagraphs = new ArrayList();

// Pass the array to be populated when mail merge in executed.

doc.MailMerge.FieldMergingCallback = new HandleEmptyMergeParagraphs(mergedParagraphs);

// Do a test merge, this will merge every field found in the document with an empty string.

doc.MailMerge.Execute(fieldNames, ArrayList.Repeat(string.Empty, fieldNames.Length).ToArray());

// Remove the paragraphs from the document if they are empty after mail merge.

foreach (Paragraph para in mergedParagraphs)

{

if (para.ParentNode != null && string.IsNullOrEmpty(para.ToTxt().Trim()))

para.Remove();

}

public class HandleEmptyMergeParagraphs : IFieldMergingCallback

{

ArrayList mArrayList;

public HandleEmptyMergeParagraphs(ArrayList list)

{

mArrayList = list;

}

void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)

{

if(string.IsNullOrEmpty((string)args.FieldValue))

{

mArrayList.Add(args.Field.Start.ParentParagraph);

}

}

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)

{

// Do Nothing

}

}

Thanks,

Apologies for such a late response.

This code worked fine for us.

Many thanks

Bob

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


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