i want to remove some content of word document ,below is my code
- Code: Select all
- public class TestDocx4jSnippet
 {
 
 public static void main(String[] str)
 {
 try
 {
 LoadFromZipNG z = new LoadFromZipNG();
 WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) z.get(new FileInputStream(new java.io.File("C:/Users/toss/Desktop/Doc1.docx")));
 
 MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
 
 String xpath = "//w:r[w:t[contains(text(),'" + "indicator" + "')]]";
 
 List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, false);
 
 for (int i = 0; i < list.size(); i++)
 {
 org.docx4j.wml.R r = (org.docx4j.wml.R) list.get(i);
 
 org.docx4j.wml.P parent = (org.docx4j.wml.P) r.getParent();
 
 parent.getContent().remove(r);
 }
 
 ByteArrayOutputStream fos = new ByteArrayOutputStream();
 SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
 saver.save(fos);
 
 }
 catch(Exception e)
 {
 e.printStackTrace();
 }
 }
 }
i find the content that isn't removed, what' wrong with my code ?
Any info would be greatly appreciated!
i use docx4j-2.7.0.jar
the attachment is my test document


 
  News
 News Site map
 Site map SitemapIndex
 SitemapIndex RSS Feed
 RSS Feed