I am working on Apache POI to edit word documents. My main task is to fetch the text and placeholders from the paragraphs and tables and they are working fine. In one of my clients document, there is a placeholder and inside that placeholder there are texts which needs to be fetched and replaced. The issue is that the text inside the placeholder is unable to be fetched as a paragraph and hence I am unable to fetch and replace the text. The screenshot of the placeholder is attached with the question and the code I am using is as follows.
XWPFDocument wordDocx = new XWPFDocument(Files.newInputStream(Paths.get(template.getAbsolutePath())));
List<IBodyElement> elements = wordDocx.getBodyElements();
Iterator<IBodyElement> bodyIterator = elements.iterator();
bodyIterator.forEachRemaining((elem) -> {
if(PARAGRAPH.equalsIgnoreCase(elem.getElementType().name())) { //if element is a paragraph.
// extract the paragraph text and replace the placeholders.
}
else if (TABLE.equalsIgnoreCase(elem.getElementType().name())) { //if element is a table.
// iterate cell by cell and replace the image placeholders.
}
});
The placeholder is not coming as a paragraph nor as a table. Any guidance how to fetch the text from the placeholder would be highly appreciated. The screenshot of the placeholder is as follows:
I am iterating the document elements that can be seen in the code above in the question. But the text inside the placeholder that can be seen in the screenshot is unable to be fetched as a paragraph.