gpt4 book ai didi

java - Docx4j 在书签上设置值

转载 作者:行者123 更新时间:2023-12-01 14:38:30 32 4
gpt4 key购买 nike

我最近使用 docx4j,并尝试在 Word 文档(这是我的模板文件)上设置书签。

我已经看过手册,但没有找到答案: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,但此处没有设置值的方法。

有人可以帮忙吗?

最佳答案

(以某种方式)在您的交叉帖子 http://www.docx4java.org/forums/docx-java-f6/set-a-bookmark-text-t1526.html 上回答了

关于java - Docx4j 在书签上设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16238624/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com