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

Free Support Forum - aspose.com

How to move to end of a Run?

Hi team,

I want to move my cursor to end of a run.
For example:
I have paragraph like below with one word like below
PARAGRAPHTEST
And I want to to move my cursor right at the end of this word. When I tried to use getNextSibling() , I am getting Null pointer exception. By the way, I am able to move to the start of the run, but my use case is to move the cursor to the end of it.

I tried pulling the paragraph index and used movetoParagraph(index,-1) to move the cursor to last position. However, I have a problem with that. If I extract the index , and use moveToParagraph() it moves to the wrong index as it takes index of the specific section and when I move , I understand it moves to the wrong index .

So, please suggest me a way to move the cursor to the end of a Run.

Thanks,
Prasanna

@pshanmuganathan,

If getNextSibling is NULL, then most likely this is the last Run in the Paragraph. In this case, you can try using the following code:

Document doc = new Document("D:\\Temp\\test.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Run targetRun = doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0);
if (targetRun.getNextSibling() != null)
{
    builder.moveTo(targetRun.getNextSibling());
}
else
{
    builder.moveTo(targetRun.getParentParagraph());
}

builder.write("new");

doc.save("D:\\temp\\awjava-18.11.docx");

Hope, this helps.