【发布时间】:2010-08-18 16:57:53
【问题描述】:
我需要使用 OpenOffice Java API 来复制文档部分并将其粘贴到另一个文档部分。到目前为止,我已经设法复制了源文档部分的文本并将其粘贴到目标文档的部分(参见下面的示例)。
但是,问题在于非文本元素(图形、格式、表格等)没有粘贴到目标文档上。
我用来提取源部分文本的代码是:
// 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 教程应该会有所帮助:Get a content and transfer it to another document.
标签: java openoffice.org openoffice-writer uno odf