2013-04-26 47 views
0

我最近使用的是docx4j,我试图在Word文档上设置书签(这是我的模板文件)。Docx4j在书签上设置一个值

我已经看到了手册,但我没有找到答案:S

我使用的是2.8.1版,我基于代码可用http://www.docx4java.org/forums/docx-java-f6/bookmarks-and-templates-advice-t681.html(感谢,freemink)得到一个书签。

PbookmarkedParagraphInPart = findBookmarkedParagraphInPart(documentPart, "bookmarktest"); 

    // 3. copy the found paragraph to keep styling correct 
    P copy = (P) XmlUtils.deepCopy(bookmarkedParagraphInPart); 

    String ptext = "Testing"; 

    // replace the text elements from the copy 
    List<?> texts = getAllElementFromObject(copy, Text.class); 
    if (texts.size() > 0) { 
    Text textToReplace = (Text) texts.get(0); 
    textToReplace.setValue(ptext); 
    } 

    // add the paragraph to the document 
    bookmarkedParagraphInPart.getContent().add(copy); 

有了这个代码我ptext上设置书签的位置,但不是里面的书签:/

我也找回了CTBookmark但是没有方法在这里设置一个值。

有人可以帮忙吗?

回答