For Each Group

Hi Team,

Please check the attached files.
BI Publisher Output.zip (59.1 KB)

The attached files have been created using Oracle BI Publisher.
In BI Publisher we have a feature called for-each-group. I searched your documents and forum section, but was unable to find anything related.

Please let me know how can i have a similar output in Aspose.
Let me know if you need more information regarding this.

Thanks and regards
Sukesh

@sukesh.kotian,

Thanks for contacting support.

As per my understanding, the input RTF file has mail merge fields and then you are filling the data from XML file and finally generating the output in PDF format. Please confirm the requirement so that we can reply accordingly.

@codewarior,

I’m not sure about that. But the RTF was generated using Oracle BI Publisher.
Please check the attached image for more info.
BI Publisher Screenshot (113.3 KB)

@sukesh.kotian

Thanks for your inquiry. Please check Mail Merge feature of Aspose.Words. It contains support of Foreach Block. Hopefully it will help you to accomplish your requirements. However, if there is any difference in your requirements then please share your input document and expected output document here as ZIP file. We will look into it and will guide you accordingly.

Mail Merge (Aspose.Words)
Foreach Blocks in Mustache Template

@tilal.ahmad,

Please check the attached image of xml structure.png (90.7 KB) and Expected Output.png (52.1 KB)

Refer to the previous comments attachments for source files.

@sukesh.kotian

Thanks for sharing additional information. Please note your template contains Form fields instead of Mail Merge Field or Plain text field. You should change your template to use Mail Merge or LINQ Reporting engine accordingly.

Mail Merge
Nested Mail Merge

LINQ Reporting Engine
LINQ Template Syntax

@tilal.ahmad,

I generated template using Mail Merge as you specified.
Please check the attached Mail Merge.zip files.
I have also provided how the Expected output should look like.

Also, how do i specify the MAILMERGE TableStart: if there is nested XML as below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <REPORT> <REPORT_DATA> <REPORT_COLUMNS> <ROW num="1"> <SUPERVISOR_NAME>Brown, Paul</SUPERVISOR_NAME> <EXECUTIVE_NAME>Pipes, J David (David) - [ Chief Financial Officer ]</EXECUTIVE_NAME> <START_COUNT>1</START_COUNT> <INVOLUNTARY_TERMS>0</INVOLUNTARY_TERMS> <VOLUNTARY_TERMS>0</VOLUNTARY_TERMS> <TOTAL_TERMS>0</TOTAL_TERMS> <PERIOD>3</PERIOD> <SUPERVISOR_LEVEL>1</SUPERVISOR_LEVEL> </ROW>....

@sukesh.kotian

Thanks for your inquiry. You can get your desired output by implementing IFieldMergingCallback. Please check following code snippet, hopefully it will help you to accomplish the task.mailmerge_AW179.pdf (19.8 KB)

// Create the Dataset and read the XML.
DataSet testDs = new DataSet();
testDs.ReadXml(@"D:\Downloads\Mail Merge\Mail Merge\test.xml");
string fileName = @"D:\Downloads\Mail Merge\Mail Merge\test.rtf";
// Open the template document.
Document doc = new Document(fileName);
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldHide();
doc.MailMerge.MergeDuplicateRegions = true;
// Trim trailing and leading whitespaces mail merge values
doc.MailMerge.TrimWhitespaces = false;

// Execute the nested mail merge with regions
doc.MailMerge.ExecuteWithRegions(testDs);

// Save the output to file
doc.Save(@"D:\Downloads\Mail Merge\Mail Merge\mailmerge_AW179.pdf");
public class HandleMergeFieldHide : IFieldMergingCallback
{
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        if (e.FieldName == "SUPERVISOR_NAME")
        {
            if (supervisor == null || supervisor != e.FieldValue.ToString())
                supervisor = e.FieldValue.ToString();
            else
                e.Text = "";
        }

    }

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing.
    }
    private string supervisor = null;
}

@tilal.ahmad,

Can you please provide code for Java.

@sukesh.kotian

Thanks for your feedback. Please check following Java code for the purpose.

// Create the Dataset and read the XML.
DataSet testDs = new DataSet();
testDs.readXml("D:\\Downloads\\Mail Merge\\Mail Merge\\test.xml");
String fileName = "D:\\Downloads\\Mail Merge\\Mail Merge\\test.rtf";
// Open the template document.
com.aspose.words.Document doc = new com.aspose.words.Document(fileName);
doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldHide());

// Trim trailing and leading whitespaces mail merge values
doc.getMailMerge().setTrimWhitespaces(false);

// Execute the nested mail merge with regions
doc.getMailMerge().executeWithRegions(testDs);
                        
// Save the output to file
doc.save("D:\\Downloads\\Mail Merge\\Mail Merge\\mailmerge_AW179.pdf");

////////////////

private static class HandleMergeFieldHide implements IFieldMergingCallback {
	public void fieldMerging(FieldMergingArgs e) throws Exception {
		if (e.getFieldName() == "SUPERVISOR_NAME") {
			if (supervisor == null || supervisor != e.getFieldValue().toString())
				supervisor = e.getFieldValue().toString();
			else
				e.setText("");
		}
	}
	
	public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
		// Do nothing
	}

	private String supervisor = null;
}

@tilal.ahmad,

This code is not dynamic right. This would just work for one template.
Doesn’t Aspose support For Each Group like how Oracle BI Publisher supports?

@sukesh.kotian

Thanks for your feedback.

I am afraid we are unable to get your point. You have to write code once for any template.

Please note Aspose.Words for Java supports Mail Merge and LINQ Reporting Engine. It does not support Oracle BI Publisher template. As suggested above, you need to change your template for using Aspose.Words for Java Mail Merge or LINQ Reporting Engine feature. Please confirm can we use Oracle BI Publisher template for Mail Merge in MS Word?

@tilal.ahmad,

You have still not understood my requirement.

FYI, I’m not using Oracle BIP template in Aspose. I’m just asking if you have a similar functionality which i’ve been mentioning from the beginning.

Also, our customers will be creating templates with grouping. It would be good if you guys provide it internally like how Oracle BIP has for-each-group. We can’t write java code for each and every template which they will create.

Let me know if you’re still unable to understand my requirement.

@sukesh.kotian

Thanks for your feedback. In addition to nested mail merge, you can also use LINQ Reporting Engine to display sequential data in your document. Please check following LINQ Reporting Engine documentation links hopefully it will serve the purpose.

[Outputting Sequential data(LINQ)]https://docs.aspose.com/words/java/outputting-sequential-data/
Typical Templates