@Test
public void test23() throws Exception {
Document document = new Document("C:\\Users\\thh\\Desktop\\参考文献-测试.docx");
int i = 0;
for (Paragraph paragraph : document.getFirstSection().getBody().getParagraphs()) {
if (i++ > 0) {
String text = paragraph.toString(SaveFormat.TEXT).trim();
System.out.println(text);
if (!text.isBlank()) {
paragraph.getRuns().clear();
paragraph.getRuns().add(new Run(paragraph.getDocument(), "test text"));
}
}
}
document.save("src/main/resources/docx/templates/result.docx", SaveFormat.DOCX);
}
I have a field like this in my document, how can I replace clearing all runs in the paragraph and then re-adding the text. Or how to convert this field into normal text first
参考文献-测试.docx (11.8 KB)