| View previous topic :: View next topic |
| Author |
Message |
mikepb78 General User


Joined: 22 Jun 2005 Posts: 37
|
Posted: Mon Nov 20, 2006 12:11 am Post subject: How to insert a external ole document [java hack] |
|
|
Having tried and failed to use openoffice api to do this, i have found a hackish way
of inserting ole objects into openoffice text documents.
| Code: |
/**
* Inserting a ole document into a text document.
*
* @param pobjText A handle to the postion you want to insert the ole object.
* @param pstrFileName The file you want to insert.
*/
public void insertOLEObject(Object pobjText, String pstrFileName) {
OpenOfficeDocument objInsertDocument = new OpenOfficeDocument();
try {
/**
* Move cursor here
*/
selectObject(QI.XTextDocument(this.mxDoc), pobjText);
/**
* Open and copy from OLE object
*/
objInsertDocument.openDoc(pstrFileName);
objInsertDocument.selectAll();
objInsertDocument.copySelection();
objInsertDocument.closeDoc(false);
objInsertDocument = null;
/**
* Paste in current document
*/
paste();
} catch(Exception e) {
throw new RuntimeException(e);
} finally {
if (objInsertDocument != null) {
objInsertDocument.closeDoc(false);
}
}
}
private void selectAll() {
try {
executeDispatch(this.mxDoc, ".uno:SelectAll", new PropertyValue[0]);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
/**
* Copies the selection to the clipboard.
*/
public void copySelection(){
try {
executeDispatch(this.mxDoc, ".uno:Copy", new PropertyValue[0]);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
/**
* Pastes from clipboard to current position.
*/
public void paste() {
try {
executeDispatch(this.mxDoc, ".uno:Paste", new PropertyValue[0]);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
/**
* Executes a dispatch command.
*
* @param pobjDoc A handle to the current document
* @param pstrCommand The command to execute
* @param pobjProperties Any properties.
*/
public void executeDispatch(Object pobjDoc, String pstrCommand, PropertyValue[] pobjProperties) {
try {
XModel xModel = QI.XModel(pobjDoc);
XController xController = xModel.getCurrentController();
XFrame xFrame = xController.getFrame();
XDispatchProvider calcDispatchProvider = QI.XDispatchProvider(xFrame);
Object oDispatchHelper = this.mxRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", this.mxRemoteContext);
XDispatchHelper dispatchHelper = QI.XDispatchHelper(oDispatchHelper);
dispatchHelper.executeDispatch(calcDispatchProvider, pstrCommand, "", 0, pobjProperties);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
|
|
| Back to top |
|
 |
Grinvon General User

Joined: 16 Apr 2008 Posts: 29
|
Posted: Mon Apr 28, 2008 9:30 am Post subject: |
|
|
Whats mean "QI"?? _________________ -= DUNKELHEIT =- |
|
| Back to top |
|
 |
allirpa General User

Joined: 21 Aug 2008 Posts: 13 Location: Philippines
|
Posted: Wed Mar 04, 2009 6:17 pm Post subject: |
|
|
does this work?
how about inserting an object, say an equation, from a different editor to open office writer?
anyone know how? |
|
| Back to top |
|
 |
Johny Walker Newbie

Joined: 20 Apr 2009 Posts: 1
|
Posted: Thu Apr 23, 2009 6:04 am Post subject: |
|
|
Thanks for the information I will try this and post here if it works or no. _________________ Fap Evolution! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|