insert
document
Tobias Krais
How to insert a document in an other one?
import {%see com.sun.star.document.XDocumentInsertable};
import {%see com.sun.star.lang.XComponent};
import {%see com.sun.star.text.XText};
import {%see com.sun.star.text.XTextCursor};
import {%see com.sun.star.text.XTextDocument};
import {%see com.sun.star.uno.UnoRuntime};
/**
* Inserts a document a the cursors point.
* @param unoDocumentURL File name that is UNO URL conform.
* How to create this, see {%internal ../Office/Office.CreateUNOCompatibleURL.snip}
*/
public void insertDocument(String unoDocumentURL) {
// How to get the XComponent, see {%internal ../Office/Office.OpenDocumentFromURL.snip}
{%see com.sun.star.text.XTextDocument|XTextDocument} xTextDocument = ({%see com.sun.star.text.XTextDocument|XTextDocument})
UnoRuntime.queryInterface({%see com.sun.star.text.XTextDocument|XTextDocument}.class, xComponent);
{%see com.sun.star.text.XText|XText} xText = xTextDocument.getText();
// create a text cursor from the cells XText interface
{%see com.sun.star.text.XTextCursor|XTextCursor} xTextCursor = xText.createTextCursor();
{%see com.sun.star.document.XDocumentInsertable|XDocumentInsertable} xDocInsert = ({%see com.sun.star.document.XDocumentInsertable|XDocumentInsertable})
UnoRuntime.queryInterface({%see com.sun.star.document.XDocumentInsertable|XDocumentInsertable}.class, xTextCursor);
try {
xDocInsert.insertDocumentFromURL(unoDocumentURL, null);
}
catch (Exception e) {
if (debug > 1)
e.printStackTrace();
}
}
Initial version