我需要使用OpenOffice Java API复制文档部分并将其粘贴到另一个文档部分。到目前为止,我已经设法复制源文档部分的文本并将其粘贴到目标文档的部分上(请参阅下面的示例)。使用OpenOffice Java API(UNO API)将整个ODT(OpenOffice Writer)文档部分复制到其他文档中
但是,问题在于非文本元素(图形,格式,表等)不会粘贴到目标文档上。
我已经用于提取源部分的文本中的代码是:
// Read source file text
XComponent xComponentSource = this.ooHelper.loadDocument("file://" + fSource);
// Get sections
XTextSectionsSupplier textSectionsSupplierSource = (XTextSectionsSupplier)UnoRuntime.queryInterface(XTextSectionsSupplier.class, xComponentSource);
XNameAccess nameAccessSource = textSectionsSupplierOrigen.getTextSections();
// Get sections by name
XTextSection textSectionSource = (XTextSection)UnoRuntime.queryInterface(XTextSection.class, nameAccessOrigen.getByName("SeccEditable"));
//Get section text
String sectionSource = textSectionSource.getAnchor().getString();
要粘贴在目标部分中的文本,该代码选择部分是相同的,并予设定的串:
textSectionDest.getAnchor().setString(sectionSource);
我已经阅读了API Javadoc,但我还没有找到任何方法来复制整个部分。有什么办法可以做到吗?
该OOOForum教程应该帮助:[获取内容并将其传输到另一个文档](http://www.oooforum.org/forum/viewtopic.phtml?t=71000)。 – 2011-03-02 15:51:24