Sure you can.
Do it in Word, then unzip the docx and look at the markup created. Duplicated that using docx4j.
It is currently Thu Jul 09, 2026 1:44 pm
News of docx4j List<Object> texts = getAllElementFromObject(template.getMainDocumentPart(), Text.class);
replacePlaceHolders(texts, mappings);
private static void replacePlaceHolders(List<?> texts,Map<String, String> mappings){
for (Object object : texts) {
Text textElement=(Text)object;
String textToReplace=textElement.getValue();
if(mappings.keySet().contains(textToReplace)){
textElement.setValue(mappings.get(textToReplace));
}
}
}
Total posts 10228 • Total topics 2885 • Total members 2108