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

Free Support Forum - aspose.com

Add text to table (without builder or bookmark)

Is it possible to add text directly to a table cell without using builder or bookmark?

Table modelBody = (Table)srcDoc.GetChild(NodeType.Table, 1, true).Clone(true);

modelBody.Rows[5].Cells[0].InsertAfter(“My Text”); <- how to make something like this?

Thanks.

Hi Sunny,

Thanks for your inquiry. Following code example shows how to insert a paragraph at the end of a cell.

Document doc = new Document(MyDir + "in.docx");

Table modelBody = (Table)doc.GetChild(NodeType.Table, 0, true);

Paragraph para = new Paragraph(doc);

para.AppendChild(new Run(doc, "My Text"));

modelBody.Rows[5].Cells[0].Paragraphs.Add(para);

doc.Save(MyDir + "Out.docx");

Following code example shows how to append some text at the end of last paragraph.

Document doc = new Document(MyDir + "in.docx");

Table modelBody = (Table)doc.GetChild(NodeType.Table, 0, true);

modelBody.Rows[5].Cells[0].LastParagraph.AppendChild(new Run(doc, "My Text"));

doc.Save(MyDir + "Out.docx");

You may also use CompositeNode.InsertAfter/CompositeNode.InsertBefore to insert the specified node immediately after/before the specified reference node. Please let us know if you have any more queries.