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

Free Support Forum - aspose.com

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":[

  1. {
    • "[TABLE]":[
      1. [
        1. "22868452",
        2. "08/14/2015",
        3. "08/14/2015",
        4. "DRAW",
        5. "$1,500.00"
        ]
      ]
    },
  2. {
    • "[FEES]":[
      1. [
        1. "22868476",
        2. "08/14/2015",
        3. "08/14/2015",
        4. "ORIGINATION FEE",
        5. "$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:

http://www.aspose.com/docs/display/wordsjava/Mail+Merge+with+Regions+Explained
http://www.aspose.com/docs/display/wordsjava/How+to++Execute+Mail+Merge+with+Regions

I hope, this helps.

Best regards,