Use OpenOffice Java API (UNO API) to copy the whole ODT (OpenOffice writer) document part to other documents

I need to use the OpenOffice Java API to copy a document part and paste it into another document part So far, I have managed to copy the text of the source document section and paste it into the target document section (see the example below)

However, the problem is that non text elements (graphics, formats, tables, etc.) will not be pasted on the target document

The code I use to extract the source text is:

// 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();

To paste the text into the target part, the code for selecting the part is the same. I set the string:

textSectionDest.getAnchor().setString(sectionSource);

I've read the API Javadoc, but I can't find any way to copy the whole part Is there any way?

Solution

I have the same problem I finally solved it by creating two cursors, one at the beginning of the content I want to copy, then using the other at the end of the content, and then expanding the cursor selection of the first to the second This uses the gotorange method on the first cursor, passes in the second cursor, and uses true to tell it to extend the selection

Cursor example: http://api.openoffice.org/docs/DevelopersGuide/Text/Text.xhtml#1_3_1_1_Editing_Text

Then I created an AutoText container, group and element containing the selection Use the applyto method of automatic text entry to insert / paste the content to the cursor position I use guid as the name of the AutoText container, so it is unique, and then delete the container when I finish

Examples of AutoText: http://api.openoffice.org/docs/DevelopersGuide/Text/Text.xhtml#1_3_1_6_Auto_Text

I can publish my code if you like, but it is written in Python

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>