Setting text in new word .doc table cell

Hi,

How do I insert text into a newly created table cell in a word document (.doc and .docx). I can create the cell using the following code but can’t find insert text into it.

Row lastRow = table.getLastRow();
Node newCell = lastRow.insertAfter(new Cell(document), null);

Thanks in advance.

Éamonn

Hello
Thanks for your request. You can try using the following code:

Document doc = new Document("C:\\Temp\\in.docx");
Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
Row lastRow = table.getLastRow();
Cell newCell = (Cell) lastRow.insertAfter(new Cell(doc), null);
Paragraph currentPara = new Paragraph(doc);
Run currentRun = new Run(doc, "Content");
currentPara.appendChild(currentRun);
newCell.appendChild(currentPara);
doc.save("C:\\Temp\\out.docx");

Also I think in your case you can try using MailMerge with region feature, it is the best way to fill the document with data. Please see the following link:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/
Best regards,