- Code: Select all
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));
}
}
}
surprisingly in the above code textElement.getValue(); never returns ${paceholder1}.
below is document.xml , word replaces my place holder to below
- Code: Select all
<w:r w:rsidR="006F02F0">
<w:rPr>
<w:b/>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>${</w:t>
</w:r>
<w:r w:rsidR="006E3760">
<w:rPr>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>paceholder1</w:t>
</w:r>
<w:r w:rsidR="006F02F0">
<w:rPr>
<w:szCs w:val="24"/>
</w:rPr>
<w:t>}</w:t>
</w:r>
please suggest me is there any way to avoid this, tell word not to split my placeholder ?