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

Free Support Forum - aspose.com

MailMerge doesn't work

MailMerge.Execute throws "The stack is full" exception since 9.8.0.0 till 10.0.0.0 version.
And it doesn't merge all MailMerge fields without any exception since 10.1.0.0 version - just skips more then half of them.
MailMerge.DeleteFields() also doesn't work since 10.1.0.0.
My question: when you will make stable version? I need to use HtmlSaveOptions.ExportHeadersFootersMode which exists since 9.8.

Hello

Thanks for your inquiry. Could you please attach your document and code here for testing? I will check the problem on my side and provide you more information.

Best regards,

Here you are.
Please note that problem reproduces only when I save to pdf.
doc.Save(ms, SaveFormat.Pdf);
:)
And evrysing ok when doc.Save(ms, SaveFormat.doc).

Hi

Thanks for your request. You should call Document.UpdatePageLayout before saving document to PDF to resolve the problem. Please see the following code:

Document doc = new Document("C:\\Temp\\template.doc");

// Execute mail merge here

// …………………………………..

doc.UpdatePageLayout();

doc.Save("C:\\Temp\\out.pdf");

The problem is caused because when you execute mail merge, Aspose.Words automatically updates fields in the document. Updating fields also runs updating page layout and the layout is cached. So changes made after updating page layout does not appear in the output PDF. So you should simply rebuild document layout to resolve the problem.

Best regards,

Thanks a lot, this helps with merge fields. Why are you change old behavior when you were writing new version?
And now there is another problem: the first grid populate twice on first and second pages, though in template it appears only one time.

Hi

Thanks for your request. Previously, it was required to update page layout to be able to update TOC fields. Currently, since upon updating fields, Aspose.Words also updates page layout, this is not required. So to update TOC, you need only update fields.

Regarding the second problem, This occurs because when you execute simple mail merge, the data source contains two rows, that is why template is copied for the second record. To resolve the problem, you should correct your code as shown below:

private void fillDataTable(DataTable dt, Int32 rowCnt)

{

for (Int32 i = 0; i < rowCnt; i++)

{

DataRow dr = dt.NewRow();

foreach (DataColumn dc in dt.Columns)

{

if (dc.DataType == typeof(float))

{

dr[dc.ColumnName] = rnd.NextDouble();

}

else if (dc.DataType == typeof(String))

{

dr[dc.ColumnName] = "test string" + Convert.ToDecimal(rnd.NextDouble()).ToString();

}

else if (dc.DataType == typeof(DateTime))

{

dr[dc.ColumnName] = DateTime.Now.AddHours(rnd.NextDouble()).ToString();

}

}

dt.Rows.Add(dr);

}

}

Best regards,

Thanks, you are right. There should be only one row but I didn’t catch why in case when I have 2 row in DataTable for simple merge, appears twice grid which is used in ExecuteWithRegions method. Reasonable to assume that second grid should appears twice instead first one. Am I right? or I missed something?

Hi

Thanks for your request. The second table is also there. It is absolutely positioned and after copying appears behind the first table.

Best regards,

Got it, thanks.