How can i separate paragraph and Add_In Field in two paragraph?

@alexey.noskov hi alexey, bump into another problem :<


this is the correct form with eyeball. however, when i display the field. it shows like :

so when i thought i was dealing with the paragraph ‘参考文献’ , i actually was dealing with the whole field code.
but when i add a newline between them. like this :

the actual display is :

so my question is : how can i process them separately ?

here is the text docx.
test.docx (20.8 KB)

@Madecho Field in MS Word document are represented using several nodes that are children of paragraph:

Please see our documentation to learn more about fields:
https://docs.aspose.com/words/java/introduction-to-fields/

what’s the difference compared with this file


text2.docx (57.3 KB)

i mean, if there’s a way, that i can convert the first file 's format from


to

how can i achieve this ?

@Madecho Unfortunately, your requirements are not quite clear. The screenshots are not very informative. Could you please attach your input and expected output document in DOCX format, so they can be compared.

ah, the attachment file is text2.docx. this is what i want text.docx to be

@Madecho You can use the following code:

Document doc = new Document("C:\\Temp\\in.docx");
// Move the field and content after it to the next paragraph.
Paragraph current = doc.getFirstSection().getBody().getFirstParagraph();
Field f = current.getRange().getFields().get(0);
Paragraph nexPara = (Paragraph)current.getNextSibling();
while (current.getLastChild() != f.getStart())
    nexPara.prependChild(current.getLastChild());
nexPara.prependChild(f.getStart());
doc.save("C:\\Temp\\out.docx");
1 Like