@mp2
Please clone the table rows and insert the content as shown below to get the desired output. Hope this helps you.
Document doc = new Document(MyDir + "template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2016);
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
int rowcount = table.getRows().getCount();
RowCollection rows = table.getRows();
System.out.println("Total Rows in Word= " + rowcount);
/*
* for (int i = 0; i < rowcount; i++){ CellCollection cells =
* rows.get(i).getCells(); for (int j = 0; j < cells.getCount(); j++)
* System.out.println( "Row: " + i + ", Cell: " + j + " - " +
* cells.get(j).getText()); }
*/
builder.moveToCell(0, 1, 1, 0);
builder.write("Aug 01, 2019");
builder.moveToCell(0, 2, 1, 0);
builder.write("Aug 15, 2019");
builder.moveToCell(0, 3, 1, 0);
builder.write("Logitech Technologies");
builder.moveToCell(0, 4, 1, 0);
builder.write("ENDS");
// new product specific attributes row - this is a merged cell with grey background
// we need this so we can add multiple products using this clone after we add multiple attributes rows
Row productRowHead = (Row) rows.get(5).deepClone(true);
Row productRowData = (Row) rows.get(6).deepClone(true); //clone the last empty row so we can add new text
for(Cell cell : productRowHead.getCells())
{
if(cell.getFirstParagraph().getRuns().getCount() > 0)
{
Run run = (Run)cell.getFirstParagraph().getRuns().get(0).deepClone(true);
run.setText("");
cell.removeAllChildren();
cell.ensureMinimum();
cell.getFirstParagraph().getRuns().add(run);
}
}
table.appendChild(productRowHead);
builder.moveToCell(0, 7, 0, 0);
builder.write("New inserted Product Name");
table.appendChild(productRowData);
builder.moveToCell(0, 8, 0, 0);
builder.write("Submission Tracking Number");
builder.moveToCell(0, 8, 1, 0);
builder.write("STN 1222");
table.appendChild((Row)rows.get(6).deepClone(true));
builder.moveToCell(0, 9, 0, 0);
builder.write("Submission Tracking Number");
builder.moveToCell(0, 9, 1, 0);
builder.write("STN 1222");
table.appendChild((Row)rows.get(6).deepClone(true));
builder.moveToCell(0, 10, 0, 0);
builder.write("Submission Tracking Number");
builder.moveToCell(0, 10, 1, 0);
builder.write("STN 1222");
doc.save(MyDir + "merged table.docx");