gpt4 book ai didi

java - 无法从文本文档检索 XBookmarksSupplier

转载 作者:行者123 更新时间:2023-12-01 15:18:28 29 4
gpt4 key购买 nike

我有各种文本文档(.odt、.doc)等,我将它们用作模板,使用 Java 用文本填充它们。为了实现这一目标,我已将 TextFields 添加到文档中要插入文本的每个位置,并枚举 TextFields 集并为其分配值。然而,我真正想做的是,因为这些文档仅用于打印,所以能够使用书签而不是文本字段(当未填充时,文本字段仍然是空的,看起来很有趣)。但是,无论我在文档模板上手动插入多少书签,每当我尝试检索文档的 XBookmarksSupplier 时,我都会得到一个空值,即

XBookmarksSupplier bookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class, document);

为空。参数 document 是我通过创建文档的内存副本获得的 XComponent,我通过以下方式将其用作模板:

XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop); 

List<PropertyValue> props = new ArrayList<PropertyValue>();
PropertyValue p = null;

p = new PropertyValue();
p.Name = "AsTemplate";
p.Value = new Boolean (true);
props.add(p);

p = new PropertyValue();
p.Name = "DocumentTitle";
p.Value = "New doc";
props.add(p);

p = new PropertyValue();
p.Name = "Hidden";
p.Value = new Boolean(true);
props.add(p);

PropertyValue[] properties = new PropertyValue[props.size()];
props.toArray(properties);

XComponent document = null;

String templateFileURL = filePathToURL(templateFile);
document = loader.loadComponentFromURL(templateFileURL, "_blank", 0, properties);

最佳答案

好吧,我终于明白了。通过使用 Eclipse 自动建议,我错误地导入了 com.sun.star.sdb.XBookmarksSupplier 而不是 com.sun.star.text.XBookmarksSupplier 这是正确的类。由于各种复制粘贴,我的所有测试都使用了相同的错误类。

关于java - 无法从文本文档检索 XBookmarksSupplier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11309235/

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