Mail merge is losing fields from the datatable

Hi,

I am using Aspose Word to do a mail merge from a datatable. The only trouble is, when I run it (there are about 300 people in the datatable), some of the people are removed and others are duplicated in their place. I have debugged through and checked and the correct information is in the datatable, right up to when I pass it in. I have downloaded the latest version from your site and that hasn't made any difference either.

The code that I am using is as follows:

protected void CreateLabels(DataTable m_search)

{

//Open the template document

Document doc;doc = doc = new Document(Server.MapPath("~/NQTManager/Labels/LabelsTemplate2.doc"));

//Perform the mail merge

doc.MailMerge.Execute(m_search);

doc.Save("labels2000.doc", SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

}

Thanks for your help

Richard

Hi Richard,

Please attach the template document you are using. We need it to be able to reproduce the problem. On Aspose forums all attachment are private and visible only to Aspose team members.

Thanks ahead,

Hi Vladimir,

Please see attachment.

Thanks

Richard

Yes, it indeed behaves strange. As far as I can see in my test, the first two cells on a page get duplicated and one is always lost between pages.

I've managed to bypass the duplication by removing the first row and adding a row to the end, but the one between pages still gets lost.

Please allow several days for working out a fix or workaround.

Regards,

OK, thanks a lot. I'll wait to hear back from you then.

Regards,

Richard

Hi,

How is this going? Sorry to hassle you, but my client is really on at me to get this resolved by Christmas.

Thanks,

Richard

I've finally figured what's wrong with your template. All cells in it, except first, look like this:

{MERGEFIELD FirstName}
{MERGEFIELD LastName}
{MERGEFIELD Role}
{MERGEFIELD SchoolName}
SchoolNumber:{MERGEFIELD SchoolNumber}
{NEXT}

But {NEXT} is a field telling Aspose MailMerge process to get next record from data source. It should be put in in the beginning of cell text, like

{NEXT}
{MERGEFIELD FirstName}
{MERGEFIELD LastName}
{MERGEFIELD Role}
{MERGEFIELD SchoolName}
SchoolNumber:{MERGEFIELD SchoolNumber}

That way you fill first cell, move to the next row in your datatable, fill second cell etc.

In your template you were filling the first cell, filling the second cell with the same data and only then moving to second row in your datatable. In the end of the page Aspose MailMerge engine was moving to next row following {Next} instruction in the end of the last cell of your page, and then the engine moved to the next row once more automatically as it was the end of your template and it had to start filling it over again.

Thus, after filling of the template the first two cells were duplicated, and the one between the pages was lost.

Please mind, that the {NEXT} field is not visible in your cells even when you toggle field view by ALT-F9, because the whole text does not fill in the size of the cell. You need to increase row height to make {NEXT} field viewable and then move it to the beginning of the cell. You need to do this operation with all cells except the first.