2013-04-26 43 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但是沒有方法在這裏設置一個值。

有人可以幫忙嗎?

回答