Changing Paragraph Formatting

I am trying to add text at the end of a document. In the my FormatText.docx is a single paragraph that is underlined. When writing the new text I don’t want it to be underline so I am removed it using setUnderline(Underline.NONE) but it doesn’t seem to take any effect. The new paragraph is always underlined as well. What is the best approach to remove the formatting? I would like to keep the font type just remove the style. (underlining/bolding).

Document doc = new Document("FormatTest.docx");
DocumentBuilder documentBuilder = new DocumentBuilder(doc);
documentBuilder.moveToDocumentEnd();
documentBuilder.insertParagraph();
documentBuilder.getFont().setUnderline(Underline.NONE);
documentBuilder.write("test");
doc.save("FormatTestResult.docx");

@faith113 Could you please attach your input document here for testing? We will check the issue and provide you more information.

Here you are Alexey, thanks.

FormatTest.docx (15.3 KB)

@faith113 Thank you for additional information. I tested your code and the new paragraph is not underlined on my side:
FormatTest.docx (15.3 KB)
out.docx (12.7 KB)

Document doc = new Document("C:\\Temp\\in.docx");
DocumentBuilder documentBuilder = new DocumentBuilder(doc);
documentBuilder.moveToDocumentEnd();
documentBuilder.insertParagraph();
documentBuilder.getFont().setUnderline(Underline.NONE);
documentBuilder.write("test");
doc.save("C:\\Temp\\out.docx");

Thanks Alexey, it looks like I made some mistakes when testing, I was using:

documentBuilder.getCurrentParagraph().getParagraphFormat().getStyle().getFont().setUnderline(Underline.NONE);

when I ran the test instead of:

documentBuilder.getFont().setUnderline(Underline.NONE);

It does work now. Thank you!

@faith113 It is perfect that you managed to resolve the problem. documentBuilder.getCurrentParagraph().getParagraphFormat().getStyle() changes the font of the style applied to the paragraph and documentBuilder.getFont() changes formatting applied to the text explicitly. In your case text underline is applied explicitly.