Merged fields appear when there is no data


#1

I created a doc template with say 20 rows of merged fields records. In the event where there is only say 8 records, the Merged field names are shown for the remaining 12 rows. How can I tell it not to display when there is no data?

Example:
Ana Trujillo Emparedados y helados
Avda. de la Constitución 2222
México D.F.05021
Mexico

?CompanyName?
?Address?
?City??PostalCode?
?Country?
( Without data, how to get rid of this after merging data? )

Thanks,
Ben


#2

Hi Ben,

You are right, at the moment Aspose.Word leaves fields for which it cannot find data alone. I left it this way thinking maybe someone wants to do more than one MailMerge pass and thus merge with data from different sources. But it’s probably not such a good idea after all. I’ll change this to remove the unpopulated fields (or maybe provider user with an option to specify what to do) by the next beta release next week.

In the meantime you can work around the problem. Assuming your program knows many rows you have in the template you can add some empty rows to the end of the data set to match the number of records you have in the template, something like this:

while (orderDetails.Rows.Count < MaxInvoiceDetails)
orderDetails.Rows.Add(orderDetails.NewRow());


#3

Hello there,

"I’ll change this to remove the unpopulated fields (or maybe provider user with an option to specify what to do) by the next beta release next week."

Is the above feature avaiable in Aspose.Word 1.2 Beta 1 or Beta 2?

Thanks,
Ben


#4

Sorry this feature didn’t go out in 1.1.2, but it will be available in just 1-2 days (together with a solution for the extra spaces you mentioned in the other topic).


#5

I definately think leaving in the merged fields should be an option, as it is essential for those who want multiple merges. Maybe a flag on the function call - or two sorts of merges, like an IntermediateMerge (which leaves in the <<>>) or Final Merge (removing unused <<>>)


#6

Aspose.Word 1.1.3 is out and provides Document.MailMerge.DeleteFields() method for this purpose.


#7

Hi Romank,

I’ve tried the Document.MailMerge.DeleteFields() method. It works great for templates using the <> tag to indicate next reocrd, but for template using the <> tag, it doesn’t get deleted.

Before applying:
-------------------
?CoName?
?RepName?
?Title?
?Addr?

?Next Record??CoName?
?RepName?
?Title?
?Addr?

After applying:
-----------------
?Next Record?

Can the <> tag be deleted?

Many Thanks,
Ben


#8

Download Aspose.Word 1.1.4 which deletes both MERGEFIELD and NEXT fields from the document.


#9

Thanks. It works now.

Ben