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

Free Support Forum - aspose.com

Updating structured document tags deleting text

I am updating the Rich Text document tags using Java words but its removing the cell in a table.
rich tags.zip (16.2 KB)

Attached the Java and word file…

appreciate help
thank you

@mp2

You are facing this issue because you are removing the child nodes of content control of type Cell. Please use the following modified code to fix this issue.

private static void updateRichText(Document doc, StructuredDocumentTag sdt, String txtVal) {

    Run run = new Run(doc);
    run.setText(txtVal);

    if( sdt.getLevel() == MarkupLevel.INLINE)
    {
        sdt.removeAllChildren();
        sdt.getChildNodes().add(run);
    }
    else if( sdt.getLevel() == MarkupLevel.BLOCK)
    {
        sdt.removeAllChildren();
        Paragraph para = (Paragraph) sdt.appendChild(new Paragraph(doc));
        para.getRuns().add(run);
        sdt.getChildNodes().add(para);
    }
    else if( sdt.getLevel() == MarkupLevel.CELL)
    {
        if(sdt.getFirstChild().getNodeType() == NodeType.CELL)
        {
            Cell cell = (Cell)sdt.getFirstChild();
            cell.removeAllChildren();
            cell.ensureMinimum();
            Paragraph para = ((Cell)sdt.getFirstChild()).getFirstParagraph();
            para.getRuns().add(run);
        }
    }
}