removing a group section when no data is available

Hi,

I was wondering if there is a way to remove a complete group section (BeginGroup/EndGroup) based on the group name?


I have attached a sample doc file.

Thanks

Attachment: Bicycle_Information.1537256483_f02bb47.zip

3 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team September 18, 2018 11:22 AM UTC

Hi Ootam, 

Thank you for contacting Syncfusion support. 

With the help of RemoveEmptyGroup and RemoveEmptyParagraphs properties, we can remove an entire group or specific merge field if its mail merged values are empty respectively. Please find the code example to remove the empty group (i.e., no data is available). 
WordDocument document = new WordDocument("EmployeesTemplate.docx"); 
 
//Gets the data table as per your requriement 
DataTable table = GetDataTable(); 
 
//Removes the empty Group.  
document.MailMerge.RemoveEmptyGroup = true; 
 
// Executes Mail Merge with groups.  
document.MailMerge.ExecuteGroup(table); 
 
//Saves and closes the WordDocument instance 
document.Save("Result.docx"); 
document.Close(); 

To remove a complete group section (BeginGroup/EndGroup) based on the group name 
Kindly provide us the complete scenario for removing group section based on the group name (i.e., a specific case or condition for removing group) which will be helpful for us to provide you a prompt solution at the earliest. 

Please let us know if you have any questions. 

Regards, 
Dilli babu. 



OS Ootam Seewoogoolam September 19, 2018 09:59 AM UTC

Hi,

Please find a sample solution, you can test.

You will find even adding the line below does not remove the group

document.MailMerge.RemoveEmptyGroup = true; 



Thanks
Ootam

Attachment: Docio_Test_7f49bf8.zip


DB Dilli Babu Nandha Gopal Syncfusion Team September 24, 2018 03:04 PM UTC

Hi Ootam,

We appreciate for your patience.

On analyzing further with the given project, we have found that data set doesn’t contains table for “Bicycles” group. So, that the group elements weren’t removed while enabling RemoveEmptyGroup property. Please add the below highlighted code snippet in your sample to meet your requirement:  
            foreach (var valObject in valueObjects)  
            {  
                docParameters.DataSet.Add(new MailMergeDataTable(valObject.Key, valObject.Value));  
            }  
  
            docParameters.DataSet.Add(new MailMergeDataTable("Bicycles", new Dictionary<string, object>()));  

Please find the modified sample from here and let us know if it helps. 
 
Regards, 
Dilli babu 


Loader.
Up arrow icon