MailMerge doesn't work

Last post 08-16-2011, 9:49 AM by ivm_ivm. 8 replies.
Sort Posts: Previous Next
  •  08-12-2011, 11:20 AM 322085

    MailMerge doesn't work .NET

    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.
     
  •  08-12-2011, 1:13 PM 322103 in reply to 322085

    Re: MailMerge doesn't work

    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,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-15-2011, 9:35 AM 322330 in reply to 322103

    Re: MailMerge doesn't work

    Attachment: Present (inaccessible)
    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).
     
  •  08-15-2011, 9:50 AM 322332 in reply to 322330

    Re: MailMerge doesn't work

    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,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-15-2011, 10:43 AM 322345 in reply to 322332

    Re: MailMerge doesn't work

    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.
     
  •  08-15-2011, 11:19 AM 322351 in reply to 322345

    Re: MailMerge doesn't work

    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,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-15-2011, 11:45 AM 322354 in reply to 322351

    Re: MailMerge doesn't work

    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?
     
  •  08-15-2011, 12:00 PM 322357 in reply to 322354

    Re: MailMerge doesn't work

    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,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-16-2011, 9:49 AM 322558 in reply to 322357

    Re: MailMerge doesn't work

    Got it, thanks.
     
View as RSS news feed in XML