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

Free Support Forum - aspose.com

Issue with Nested Regions in Header and Footer

Hello,

I need the ability to perform a nested mail merge using the header and footer. Let me explain. I have created a DataSet with two tables linked together, Invoice and InvoiceDetail. In the header, I have the customer name. I also need the customer name in the footer as well. In the middle of the document I have list of items (InvoiceDetail). Here is a sample of how this looks:

– header —
<tablestart:Invoice> <<Invoice_CustomerName>> tableend:Invoice>
– end header ----

---- main body of doc ----
<tablestart:InvoiceDetail>
<<InvoiceDetail_Description>> <<InvoiceDetail_Quantity>>
<tableend:InvoiceDetail>

– footer –
<tablestart:Invoice> <<Invoice_CustomerName>> tableend:Invocie>
– end footer –

When I perform my document.executewithregions(dataset), it merges all the rows into the header and all the detail rows into the body. What I want is a separate Invoice for each customer with their order information in the middle. The hard part with this is the fact that we are also trying to merge data into the header and footer. Can someone help me figure out how to get a separate invoice on each page with the order details in the middle, having the customers name repeat in the header and footer? Many of our invoices span across multiple pages which is why we ant to use the header and footer. We print thousands of invoices at a time.

I’ve attached my sample document and here is the code below I’m using for this simple test. Here is sample code for this test:

Dim doc As New Document(“c:\INVOICE.DOCX”)

dt = New DataTable(“InvoiceMaster”)
dt.Columns.Add(“StoreIdent”)
dt.Columns.Add(“InvoiceMaster_CustomerName”)
dt.Rows.Add(1, “ABC Company”)
dt.Rows.Add(2, “ACME Security”)
dt.Rows.Add(3, “CABLE Company”)
dt300Detail = New DataTable(“InvoiceDetail”)
dt300Detail.Columns.Add(“StoreIdent”)
dt300Detail.Columns.Add(“InvoiceDetail_Description”)
dt300Detail.Columns.Add(“InvoiceDetail_Quantity”)
dt300Detail.Columns.Add(“InvoiceDetial_Price”)
dt300Detail.Rows.Add(1, “Deli Meat”, “2”, “12.99”)
dt300Detail.Rows.Add(1, “Chicken Soup”, “1”, “4.79”)
dt300Detail.Rows.Add(1, “Turkey”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Roast Beef”, “2”, “13.49”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(3, “Candy Bars”, “5”, “4.98”)
ds.Tables.Add(dt)
ds.Tables.Add(dt300Detail)
ds.Relations.Add(“Ids”, dt.Columns(“StoreIdent”), dt300Detail.Columns(“StoreIdent”), False)

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveUnusedFields Or MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions Or MailMerging.MailMergeCleanupOptions.RemoveContainingFields
doc.MailMerge.ExecuteWithRegions(ds)
doc.Save(“C:\INVOICE.PDF”, SaveFormat.Pdf)

When the above code is run, the attached Test.pdf document is created. Please help.

Thanks,
Brian



Hi Brian,

Thanks for your inquiry. Please note that HeaderFooter is a section-level node and can only be a child of Section. The TableStart and TableEnd fields must be inside the same section in the document. Please refer to the following article:
Mail Merge with Regions Explained

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Hello,

I’ve attached a new PDF called InvoiceGood.pdf which show how the final PDF should generate. Please note that the Header and Footer have mail merge fields included. We are currently passing a Dataset with the InvoiceMaster and InvoiceDetail tables. How can we get the document to only merge one record into the header and footer at a time while merging the item details into the body of the document.

At this point, I have attached all the relevant documents and my previous comments went into great detail on how we would like to get the document to print. Can your team please review and let us know how to handle this?

Thanks,
Brian
Hi Brian,

Thanks for sharing the detail. In your case, we suggest you following solution.

1) Set the "page break before" as true. See "page break before.png".
2) Add text box to paragraph after the TableStart field and insert InvoiceMaster_CustomerName mail merge field in it.
3) Add text box to paragraph before the TableEnd field and insert InvoiceMaster_CustomerName mail merge field in it. See "customer name field.png".
4) Change the position of text boxes according to your requirements.

We have attached the modified template document with this post for your kind reference. Hope this helps you.

Tahir,


Thanks for the sample document. Unfortunately, this did not resolve my issue. The sample document simply moved the Customer Name into a floating textbox outside the header and footer. I actually need the specific items in the header and footer for my process to work correctly. In the current example, when the number of invoice items exceeds the current page, the items just carry down to the next page, but I lose the header and footer on the second page. This is why I need my merge items inside the header and footer.

Can you send me an example of this working with merge tags in the header and footer, as well as merge the order data into the body of the document?

Here is some additional sample code I used for my testing:

doc = New Document(“c:\INVOICE.DOCX”)

dt = New DataTable(“InvoiceMaster”)
dt.Columns.Add(“StoreIdent”)
dt.Columns.Add(“InvoiceMaster_CustomerName”)
dt.Rows.Add(1, “ABC Company”)
dt.Rows.Add(2, “ACME Security”)
dt.Rows.Add(3, “CABLE Company”)
dt300Detail = New DataTable(“InvoiceDetail”)
dt300Detail.Columns.Add(“StoreIdent”)
dt300Detail.Columns.Add(“InvoiceDetail_Description”)
dt300Detail.Columns.Add(“InvoiceDetail_Quantity”)
dt300Detail.Columns.Add(“InvoiceDetial_Price”)
dt300Detail.Rows.Add(1, “Deli Meat”, “2”, “12.99”)
dt300Detail.Rows.Add(1, “Chicken Soup”, “1”, “4.79”)
dt300Detail.Rows.Add(1, “Turkey”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Roast Beef”, “2”, “13.49”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Chicken Taco Sandwich”, “1”, “9.99”)
dt300Detail.Rows.Add(2, “Chicken Breast”, “1”, “3.99”)
dt300Detail.Rows.Add(2, “Pickles”, “1”, “9.99”)
dt300Detail.Rows.Add(3, “Candy Bars”, “5”, “4.98”)
ds.Tables.Add(dt)
ds.Tables.Add(dt300Detail)
ds.Relations.Add(“Ids”, dt.Columns(“StoreIdent”), dt300Detail.Columns(“StoreIdent”), False)

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveUnusedFields Or MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions Or MailMerging.MailMergeCleanupOptions.RemoveContainingFields
doc.MailMerge.ExecuteWithRegions(ds)
doc.Save(“C:\INVOICE.PDF”, SaveFormat.Pdf)


Thanks,

Brian

Hi Brian,

Thanks for your inquiry. We are working over your query and will get back to you soon.