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

Free Support Forum - aspose.com

Confuse table nested

I have a problem .

Mail merge region ‘workingfield’ is badly formed. TableStart and TableEnd should be in the same section, same table row or same table cell.

Any one help me to solve this issue :slight_smile:

Hi there,

Thanks for your inquiry. If a region is used inside a table, TableStart and TableEnd must be inside the same row in the table.

Please read the simple rules when marking a region from here:
http://www.aspose.com/docs/display/wordsnet/Mail+Merge+with+Regions+Explained

i have 3 datatable

i want to make report like that


Hi,


Thanks for your inquiry. I have prepared a sample template document for you (see attached template.docx), please try executing the following code to perform nested mail merge with regions.

DataSet ds = new DataSet();

ds.ReadXml(MyDir + "data.xml");

Document doc = new Document(MyDir + @"Template.docx");

doc.MailMerge.ExecuteWithRegions(ds);

doc.Save(MyDir + @“out.docx”);


I have also attached an output document i.e. generated using the above code on my side and a test data.xml file here for your reference. I hope, this helps.

Best regards,

Hi there,

Thanks for your inquiry. In your case, I suggest you please read following documentation links.

How to Set up Relations for use in Nested Mail Merge with Regions
How to Execute Mail Merge with Regions

Please check the mail merge region code example in Aspose.Words for .NET examples repository at GitHub.

I have created a simple application for your scenario. Following code example shows how to use mail merge with regions. Input document is attached with this post. Hope this helps you.

DataTable listA1 = new DataTable("listA1");

listA1.Columns.Add("listA1Col1", typeof(string));

listA1.Columns.Add("ID", typeof(int));

listA1.Rows.Add("listA1", 1);

listA1.Rows.Add("listA2", 2);

DataTable listB1 = new DataTable("listB1");

listB1.Columns.Add("listB1Col1", typeof(string));

listB1.Columns.Add("ID", typeof(int));

listB1.Columns.Add("listA1_ID", typeof(int));

listB1.Rows.Add("listB1", 1, 1);

listB1.Rows.Add("listB2", 2, 1);

listB1.Rows.Add("listB2 listA2", 3, 2);

DataTable listC1 = new DataTable("listC1");

listC1.Columns.Add("listC1Col1", typeof(string));

listC1.Columns.Add("ID", typeof(int));

listC1.Columns.Add("listB1_ID", typeof(int));

listC1.Rows.Add("listC1", 1, 1);

listC1.Rows.Add("listC2", 2, 1);

listC1.Rows.Add("listC3", 3, 2);

listC1.Rows.Add("listC3", 4, 3);

listC1.Rows.Add("listC3", 5, 3);

DataSet dataSet = new DataSet();

dataSet.Tables.Add(listA1);

dataSet.Tables.Add(listB1);

dataSet.Tables.Add(listC1);

dataSet.Relations.Add(new DataRelation("Relation1", listA1.Columns["ID"], listB1.Columns["listA1_ID"]));

dataSet.Relations.Add(new DataRelation("Relation2", listB1.Columns["ID"], listC1.Columns["listB1_ID"]));

Document doc = new Document(MyDir + "MailMergewithRegions.docx");

doc.MailMerge.ExecuteWithRegions(dataSet);

doc.Save(MyDir + "Out.docx");


How to delete list1 if list2 and list 3 reference null


i have class RemoveEmptyRegions but i want show if list1 list2 and list 3 have reference

Hi there,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.5.0) from here.

I suggest you please use MailMerge.setCleanupOptions method with MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS flag to remove unused mail merge regions. Please check the following code snippet.

Document msdoc = new Document(MyDir

  • “in.docx”);

msdoc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS

| MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS

| MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS

| MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);



If you still face problem, please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please

    create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

i used version v14.5.0

I have attached my project here
I removed unused field by adding remove class
But i still have a 1 problem as file remove region i attached

List1 idl1,…
List2 idl2,idl1…
List3 idl3,idl2…


In case
List1 1…
List2 10,1…
List3 11,10…
Work well
But
List1 1…
List2 10,2…
List3 11,12…

List 1 still shows
I want to delete list1 value if list2 and 3 null



Hi there,

Thanks for your inquiry. I suggest you please read following documentation link for your kind reference.
http://www.aspose.com/docs/display/wordsjava/How+to++Apply+Custom+Logic+to+Unmerged+Regions

In your case, I suggest you following solution.

1) Please implement IFieldMergingCallback interface and insert bookmarks for List 1, List 2 and List 3 (name the bookmark with record IDs e.g List1_id1, List2_id1, List3_id1.
2) After performing mail merge, iterate through bookmarks and check if no bookmark exists for List 2 and List 3.
3) If no bookmark found for List2 and List 3, delete the paragraph in which bookmark of List 1 exists

Hope this helps you.