OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to insert a external ole document [java hack]

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
mikepb78
General User
General User


Joined: 22 Jun 2005
Posts: 37

PostPosted: Mon Nov 20, 2006 12:11 am    Post subject: How to insert a external ole document [java hack] Reply with quote

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
View user's profile Send private message
Grinvon
General User
General User


Joined: 16 Apr 2008
Posts: 29

PostPosted: Mon Apr 28, 2008 9:30 am    Post subject: Reply with quote

Whats mean "QI"??
_________________
-= DUNKELHEIT =-
Back to top
View user's profile Send private message
allirpa
General User
General User


Joined: 21 Aug 2008
Posts: 13
Location: Philippines

PostPosted: Wed Mar 04, 2009 6:17 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
Johny Walker
Newbie
Newbie


Joined: 20 Apr 2009
Posts: 1

PostPosted: Thu Apr 23, 2009 6:04 am    Post subject: Reply with quote

Thanks for the information I will try this and post here if it works or no.
_________________
Fap Evolution!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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