Aspose Words Java MailMergeList

How to print list of values using ImailMergeDataSource.My code is printing object in every doc.i want list to be displayed at only one doc Please fins my code and template.

String nasDirectory = "C:/Users/U383277/Desktop/";
for (int i = 0; i < 120; i++)
{
    form = new Form();
    form.setNo(i);
    form.setName("Name" + i);
    form.setDescription("Desc" + i);
    scheduleList.add(form);
}
Document templatedoc = new Document(nasDirectory + "Template.docx");
CustomMailMergerDataSource custMailMergerDtaSource = new CustomMailMergerDataSource(scheduleList);
templatedoc.getMailMerge().setUseNonMergeFields(false);
// templatedoc.getMailMerge().
templatedoc.getMailMerge().execute(custMailMergerDtaSource);
templatedoc.save(nasDirectory + "Template1.docx");
public class CustomMailMergerDataSource implements IMailMergeDataSource
{
    private List forms;
    private int mRecordIndex;
    Iterator m_iterator;
    Form m_currentForm;

    public List getFormList()
    {
        return forms;
    }

    public void setFormList(List forms)
    {
        this.forms = forms;
    }

    public int getmRecordIndex()
    {
        return mRecordIndex;
    }

    public void setmRecordIndex(int mRecordIndex)
    {
        this.mRecordIndex = mRecordIndex;
    }

    public CustomMailMergerDataSource(List forms)
    {
        super();
        this.forms = forms;
        m_iterator = forms.iterator();
    }

    public IMailMergeDataSource getChildDataSource(String arg0) throws Exception
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String getTableName() throws Exception
    {
        // TODO Auto-generated method stub
        return "Form";
    }

    public boolean getValue(String fieldName, Object[] fieldValue) throws Exception
    {
        // TODO Auto-generated method stub
        String field = null;
        if (fieldName.equalsIgnoreCase("No")) {
            field = m_currentForm.getNo() + "";
        //return true;
        } else if (fieldName.equalsIgnoreCase("Name")) {
            field = m_currentForm.getName();
        //return true;
        } else if (fieldName.equalsIgnoreCase("Description"))
        {
            field = m_currentForm.getDescription();
            //return true;
        }
        if (field != null)
        {
            fieldValue[0] = field;
            return true;
        }
        else
        {
            // field was not found
            return false;
        }
    }
    public boolean moveNext() throws Exception
    {
        // TODO Auto-generated method stub
        boolean hasNext = m_iterator.hasNext();
        if (hasNext)
        {
            m_currentForm = (Form)m_iterator.next();
        }
        return hasNext;
    }

    private boolean IsEof()
    {
        return (mRecordIndex >= forms.size());
    }
}

Hi,

Thanks for your inquiry. I have modified your template document and attached it here for your reference (see template-v1.docx). You can meet this requirement using mail merge with regions feature of Aspose.Words. Please refer to the following articles:

Mail Merge with Regions Explained

How to Execute Mail Merge with Regions

Please use templatedoc.getMailMerge().executeWithRegions(custMailMergerDtaSource) method instead. Hope, this helps.

Best regards,