i am looking for a simple way to replace a word or part of text in a docx-File.
I have already read the "Getting Started - Tutorial/howto". But I think i don't get it.
I was reading the part "Adding a paragraph of text". Is this the right one to solve my problem?
I dont want to append a new part at the bottom of the document. I want to replace a word in the middle of the text.
This is a part of the code to get the element/word/text i want.
- Code: Select all
//Auslesen der eizelnen Absätze (w:p)
String xpath = "//w:p";
try {
List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, false);
System.out.println("\nJaxbNote via Xpath\n\n");
for(int i=0; i<list.size();i++){
String p =list.get(i).toString();
if(p.equalsIgnoreCase("überschrift")){
System.out.println("ALT: "+p);
Object obj = list.get(i);
System.out.println(list.get(i).toString());
System.out.println("NEU: "+list.get(i).toString());
}
}
System.out.println("\nJaxbNote via Xpath ENDE\n\n");
System.out.println("Grüße aus Deutschland! :-)");
} catch (JAXBException e1) {
e1.printStackTrace();
}
best regards