Why the field is not connected with the number[xx] anymore?

@alexey.noskov hello dear alexey !!!

as you can see, the [34] is connected with certain ‘reference citation’ but after I process this paragraph with code ’

public void formatParagraphText(Paragraph paragraph) throws Exception {

    StyleUtils.merge(paragraph.getParagraphFormat(), styleConfigDto.getText(), StyleIdentifier.NORMAL, true);
    Run previousRun = new Run(null);
    for (int i = 0; i < paragraph.getRuns().getCount(); i++) {
        Run run = paragraph.getRuns().get(i);
        String previousRunText = previousRun.getText();
        String currentRunText = run.getText();
        if(run.getText().contains("ADDIN"))
            continue;
        StyleUtils.merge(run.getFont(), styleConfigDto.getText());
        previousRun = run;
    }
}

the ouput becomes

which is a pure text, but when I debugged to this paragraph, the getText() still shows the field content , something like ‘ADDIN’, but not as before anymore, how can I fix it? because, i just want to format the style of the content, maybe setSuperscript with number like [xx], but I dont want to lose its reference

the original file is here
上标测试_demo.docx (45.8 KB)

@Madecho If it is required to format field value, you can use the following simple code:

Document doc = new Document("C:\\Temp\\in.docx");

for (Field f : doc.getRange().getFields())
{
    if (f.getType() == FieldType.FIELD_ADDIN)
    {
        // Apply formatting to the field value.
        Node current = f.getSeparator();
        while (current != null && current != f.getEnd())
        {
            if (current.getNodeType() == NodeType.RUN)
                ((Run)current).getFont().setSuperscript(true);
            current = current.getNextSibling();
        }
    }
}

doc.save("C:\\Temp\\out.docx");
1 Like