Add rows dynamically to the Existing table in the document Template

I have a word template and there has a table with headers in it and rows need to be added dynamically from the List:

"data":[

 {
    "[TABLE]":[
       [
          "22868452",
          "08/14/2015",
          "08/14/2015",
          "DRAW",
          "$1,500.00"
]
]
},

 {
    "[FEES]":[
       [
          "22868476",
          "08/14/2015",
          "08/14/2015",
          "ORIGINATION FEE",
          "$100.00"

]
]
}
]

generating PDF through ASPOSE.Words
I need to add the rows dynamically to the existing table in the Template:

Transactions
Reference Number Transaction Date Post Date Description of Transaction or Credit Amount
[TABLE]
Add new rows
Fees
[FEES]
Add new rows
TOTAL FEES FOR THIS PERIOD [TOTALFEESPERIOD]
Interest Charged
[INTEREST]
Add new rows
TOTAL INTEREST FOR THIS PERIOD [TOTALINTEREST]
[YEAR] Totals Year-to-Date
Total fees charged in [YEAR] [YEARTOTALFEES]
Total interest charged in [YEAR] [YEARTOTALINTEREST]
NOTICE: SEE THE NEXT PAGE FOR IMPORTANT INFORMATION

My Code is

private void renderDocumentData(Document wordSourceDocument, List<HashMap> data) throws Exception {
    List childTablesList = AsposeWordUtil.*getAllChildTables*(wordSourceDocument);
    if (childTablesList != null && !childTablesList.isEmpty()) {
        for (Table table : childTablesList) {
            for (Map mapData : data) {
                for (Entry entry : mapData.entrySet()) {
                    String placeHolder = entry.getKey();
                    List rowsValueList = (List) entry.getValue();
                    if (table.getRange().getText().contains(placeHolder)) {
                        RowCollection rowCollection = table.getRows();
                        for (Row row : rowCollection) {
                            NodeCollection children = row.getChildNodes();
                            for (int ix = 0; ix < children.getCount(); ix++) {
                                Node child = children.get(ix);
                                if (child.getNodeType() == NodeType.CELL) {
                                    Cell run = (Cell) child;
                                    if (run.getText().contains(placeHolder)) {
                                        Row templateRow = run.getParentRow();
                                        for (Object cellValueListObject : rowsValueList) {
                                            List cellValueList = (List) cellValueListObject;
                                            Row newRow = (Row) templateRow.deepClone(true);
                                            newRow.getRowFormat().setAllowBreakAcrossPages(true);
                                            for (int i = 0; i < cellValueList.size(); i++) {
                                                String cellNewValue = (String) cellValueList.get(i);
                                                AsposeWordUtil.*replaceTextInTableCell*(newRow.getCells().get(i), cellNewValue);
                                            }
                                            table.appendChild(newRow);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

The problem, the pdf Generated is add row in over the last row of table.
Template Aspose.png

Hi David,

Thanks for your inquiry. Please refer to the “Mail Merge with Regions” functionality of Aspose.Words:

https://docs.aspose.com/words/java/types-of-mail-merge-operations/
https://docs.aspose.com/words/java/mail-merge-and-reporting/

I hope, this helps.

Best regards,