Page 1 of 1
[Solved] Insert Writer Documents in single one with Java
Posted: Sun May 19, 2013 2:20 pm
by VV_RIP
Hello! I have several documets (XComponents), but i don't know, how i can insert it into one document? After this i save document to a file.
Any help in this?
Thanks in advance.
Re: Insert Writer Documents in single document with Java
Posted: Sun May 19, 2013 3:18 pm
by RoryOF
Start a new OpenOffice document, then /Insert /File and select each file in turn, with your cursor positioned where in the new document you wish the file to be inserted.
Re: Insert Writer Documents in single document with Java
Posted: Sun May 19, 2013 11:18 pm
by VV_RIP
Can you talk in detail? I can't understand, how i can do this? What i must use for this?
Re: Insert Writer Documents in single document with Java
Posted: Tue May 21, 2013 5:42 am
by SNM90
Hi,
If they are writer documents which you want to insert, you can use the XDocumentInsertable interface whose method 'insertDocumentFromURL()' will aid you in this. If the documents to be inserted are of other types like Calc, Draw, etc, then you might want to use the service TextEmbeddedObject to directly embed the document through their CLSIDs (although I'm not sure if this technique works for existing documents like Calc, etc. I've posted a question too regarding this but have got no reply yet).
Hope I could help.
Re: Insert Writer Documents in single document with Java
Posted: Wed May 22, 2013 11:04 pm
by VV_RIP
Thanks! It solve my problem!
Code:
Code: Select all
public void addTemplate(String tempDocument) //путь к файлу
throws Exception {
XTextCursor cur = doc.getText().createTextCursor();//XTextDocument doc
cur.gotoEnd(false);
XDocumentInsertable xDocI = (XDocumentInsertable)
UnoRuntime.queryInterface(XDocumentInsertable.class, cur);
xDocI.insertDocumentFromURL((new File(tempDocument)).toURI().toString(), new PropertyValue[0]);
}