2011-10-17 2 views
1

목록 단락 (.으로 시작)을 찾고이 목록에 다른 목록 항목을 추가하려는 경우 (첫 번째 목록 요소의 텍스트에 따라 다름). 나는 새로운 단락을 만드는 많은 방법을 시도했지만, 내가 달성 한 모든 것은 새로운 목록 요소가 만들어 지지만, 단락에 org.docx4j.wml.Text 개체가 추가되어 새로운 단락이 추가된다는 것입니다. 새 단락 텍스트가 비어 있습니다. 새로운 목록 요소가 어떻게 생성되고 올바른 요소에 추가 될 수 있습니까?새 목록 항목을 목록에 추가하는 방법

  • a. 목록 요소 1 | 테스트 | // | test | b에 첨부해야한다.
  • b. // 새 항목이 만들어 지지만 텍스트가 없습니다.
  • c.
//traverse through a document 
    public List<Object> apply(Object obj) { 
     if (obj instanceof org.docx4j.wml.P) { 
      if (p.getPPr() != null) { 
      if (p.getPPr().getPStyle() != null) { 
       if ((p.getPPr().getPStyle().getVal().equals("Akapitzlist"))) { 
        //there is a list paragraph 
         ObjectFactory factory = Context.getWmlObjectFactory(); 
         Object deepCopy = XmlUtils.deepCopy(obj); 
        //Create the paragraph 
        org.docx4j.wml.P para = factory.createP(); 

        // Create the text element 
        org.docx4j.wml.Text t = factory.createText(); 
        t.setValue("|test|"); 

        // Create the run 
        org.docx4j.wml.R run = factory.createR(); 
        run.getContent().add(t); 
        para.getContent().add(run); 
        //add new paragraph to the document 
        ((org.docx4j.wml.P) obj).getContent().add(para); 

    }...} 

답변

0

내 솔루션, 그냥 증분 색인이 몸에 추가합니다. 나는 스타일을 유지하기 위해 깊은 사본을 만들고 있습니다.

public List<Object> apply(Object obj) { 


    Object deepCopy = null; 



    if (obj instanceof org.docx4j.wml.P) { 

     org.docx4j.wml.P p = (org.docx4j.wml.P) obj; 


     if (p.getPPr() != null) { 
      if (p.getPPr().getPStyle() != null) { 
       if ((p.getPPr().getPStyle().getVal().equals("Akapitzlist")) && (akapListCounter < 10)) { 

        if (((org.docx4j.wml.P) obj).getPPr().getPStyle() != null) { 
         if ((((org.docx4j.wml.P) obj).getPPr().getPStyle().getVal().equals("Akapitzlist"))) { 
          deepCopy = XmlUtils.deepCopy(obj); 
          akapListCounter++; 
          int indexOf = wmlDocumentEl.getBody().getContent().indexOf(obj); 


          List<Object> content = ((org.docx4j.wml.P) deepCopy).getContent(); 
          for (Object el : content) { 
           System.out.println("class1:" + el.getClass().toString()); 
           if (el instanceof org.docx4j.wml.R) { 
            List<Object> subc = ((org.docx4j.wml.R) el).getContent(); 
            for (Object r : subc) { 
             ((javax.xml.bind.JAXBElement) r).setValue("tetetete"); 
            } 
           } 

          }// end for 


          wmlDocumentEl.getBody().getContent().add(indexOf + 1, deepCopy); 


         } 
        }//end get style 

       } 
      } 
     } else {} 


    } 

    return null; 
} 
관련 문제