Setting text in new word .doc table cell


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.


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");

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:
Best regards,