我有各种文本文档(.odt、.doc)等等,我使用这些文档作为模板,使用Java填充文本。为了实现这一点,我在我想要插入文本的每个位置上的文档中添加了TextFields,并枚举了TextFields集并为它们赋值。但是,我真正想要做的是,因为这些文档只是为了打印,所以能够使用书签而不是TextFields (如果没有填充,它仍然是emtpy的,看起来很有趣)。然而,无论我在文档模板上手动插入多少书签,每当我试图检索文档的XBookmarksSupplier时,我都会得到一个空值,即
UnoRuntime.queryInterface(XBookmarksSupplier.class,文档( XBookmarksSupplier bookmarksSupplier = (XBookmarksSupplier) );
是空的。参数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);发布于 2012-07-04 08:57:43
我终于想明白了。通过使用Eclipse,我错误地导入了com.sun.star.sdb.XBookmarksSupplier而不是com.sun.star.text.XBookmarksSupplier,这是正确的类。由于不同的复制粘贴我所有的测试,在使用相同的错误类。
https://stackoverflow.com/questions/11309235
复制相似问题