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

Free Support Forum - aspose.com

Updating text of content control throws exception using Java

@tahir.manzoor
I am facing this exception “com.aspose.words.BookmarkStart cannot be cast to com.aspose.words.Run”.
Can u please help me to solve this problem.

PFA
Test3.zip (35.7 KB)

@rabinintig

Please remove the bookmark “_GoBack” as shown below to fix this issue.

Document doc1;
doc1 = new Document(MyDir + "test123.docx");
DocumentBuilder builder = new DocumentBuilder(doc1);
Document doc = builder.getDocument();
if(doc.getRange().getBookmarks().get("_GoBack") != null)
    doc.getRange().getBookmarks().get("_GoBack").remove();

hi @tahir.manzoor
i am facing again the same problem “com.aspose.words.BookmarkStart cannot be cast to com.aspose.words.Run”

PFA
test7.zip (34.0 KB)

@tahir.manzoor
Can u please help me to solve this problem.

@rabinintig

There are many bookmarks in your document. We suggest you please use StructuredDocumentTag.getChild method instead of StructuredDocumentTag.getFirstChild. Please check the following code snippet.

if (sdt.getSdtType() == SdtType.RICH_TEXT && sdt.getLevel() == MarkupLevel.INLINE)
{
    System.out.println("inline" + sdt.getText());
    sdt.getFirstChild().getNodeType();
    //Run run = (Run) sdt.getFirstChild().deepClone(true);
    Run run = (Run) sdt.getChild(NodeType.RUN, 0, true);
    sdt.isShowingPlaceholderText(false);
    sdt.removeAllChildren();
    run.setText("AUTO999");
    sdt.appendChild(run);
}

@tahir.manzoor
thanks tahir . it’s working fine.