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

Free Support Forum - aspose.com

Inserting a string in a paragraph

Hi,

I am getting the text/string value from a paragraph from a DOCX document, modifying the content and I want to set the modified string value to the same paragraph again.

I am getting the string using:

Paragraph.getText();

How to set the modified string to the same paragraph again ?

Regards,
Prabhaker Kr

Hi Prabhaker,

Thanks for your inquiry. All text of the document is stored in runs of text. In your case, I suggest you Run.Text property to get or set the text. You may also use following code example to remove run nodes of Paragraph and add new Run node into Paragraph.

Moreover, I suggest you please read about Aspose.Words document object model from here:
https://docs.aspose.com/words/java/aspose-words-document-object-model/

Document doc = new Document(MyDir + "in.docx");
Paragraph paragraph = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);
paragraph.getRuns().clear();
Run run = new Run(doc, "modified text");
paragraph.appendChild(run);
doc.save(MyDir + "Out.docx");