Hi Denis, It seems that the embedded object have to be edited before to access its controller. But the only way I've found to do this, is to temporarily sets it visible, then hidden again.
Here is what I found : REM ***** BASIC ***** option explicit sub main() dim component as object ' '== when the document is visisble == ' 'if the embedded object is edited : thisComponent = embedded object => gets the top component ' component = getTopParent(thisComponent) ' _proccessEmbeddedObject(component) '== when the document isn't visisble == dim currentController as object dim containerWindow as object dim args(0) as new com.sun.star.beans.PropertyValue args(0).name = "Hidden" args(0).value = true component = starDesktop.loadComponentFromUrl("file:///home/tvataire/Bureau/testEmbed.odt", "_blank", _ com.sun.star.frame.FrameSearchFlag.CREATE, args) on local error goto finally 'do something ... 'the document must be displayed to allow to change the active sheet of the embedded object currentController = component.currentController if (not isNull(currentController)) then containerWindow = currentController.frame.containerWindow containerWindow.setVisible(true) _proccessEmbeddedObject(component) containerWindow.setVisible(false) end if 'do something else... component.store() finally: component.dispose() end sub 'returns the top parent if it exists (i.e. when "aChild" is an embedded object currently edited). otherwise, returns "aChild" function getTopParent(aChild as object) as object dim result as object dim parent as object if (hasUnoInterfaces(aChild, "com.sun.star.container.XChild")) then parent = aChild.parent if (isNull(parent)) then result = aChild else result = getTopParent(parent) end if end if getTopParent = result end function sub _proccessEmbeddedObject(component as object) dim success as boolean dim anEmbeddedObject as object dim xModel as object dim embeddedObjController as object 'looks for the requested embedded object anEmbeddedObject = getEmbeddedObjectByName(component, "Objet1") 'and changes its state if needed success = editEmbeddedObject(anEmbeddedObject, true) if (success) then xModel = anEmbeddedObject.getEmbeddedObject() if (hasUnoInterfaces(xModel, "com.sun.star.frame.XModel")) then embeddedObjController = xModel.currentController if (hasUnoInterfaces(embeddedObjController, "com.sun.star.sheet.XSpreadsheetView")) then embeddedObjController.setActiveSheet(embeddedObjController.model.sheets.getByIndex(0)) end if end if editEmbeddedObject(anEmbeddedObject, false) end if end sub 'returns the embedded object named "anObjectName" if it exits, null otherwise function getEmbeddedObjectByName(XTextEmbeddedObjectsSupplier as object, anObjectName as string) dim result as object dim embeddedObjects as object if (hasUnoInterfaces(XTextEmbeddedObjectsSupplier, "com.sun.star.text.XTextEmbeddedObjectsSupplier")) then embeddedObjects = XTextEmbeddedObjectsSupplier.getEmbeddedObjects() if (embeddedObjects.hasByName(anObjectName)) then result = embeddedObjects.getByName(anObjectName) end if end if getEmbeddedObjectByName = result end function 'edits an embedded object if "bEdit" is true; otherwise quits this state 'returns true if succeed, false otherwise function editEmbeddedObject(xEmbeddedObjectSupplier2 as object, bEdit as boolean) as boolean dim requestedState as long dim success as boolean dim xEmbeddedObject as object requestedState = com.sun.star.embed.EmbedStates.RUNNING if (bEdit) then requestedState = com.sun.star.embed.EmbedStates.UI_ACTIVE end if success = hasUnoInterfaces(xEmbeddedObjectSupplier2, "com.sun.star.document.XEmbeddedObjectSupplier2") if (success) then xEmbeddedObject = xEmbeddedObjectSupplier2.getExtendedControlOverEmbeddedObject() success = (xEmbeddedObject.getCurrentState() = requestedState) if (not success) then success = changeEmbeddedObjectState(xEmbeddedObject, requestedState) end if end if editEmbeddedObject = success end function 'modifies the current state of an embedded object 'returns true if succeed, false otherwise function changeEmbeddedObjectState(xEmbeddedObject as object, expectedState as long) as boolean dim success as boolean success = supportsEmbedState(xEmbeddedObject, expectedState) if (success) then on local error goto errChangeState xEmbeddedObject.changeState(expectedState) goto noErr errChangeState: success = false noErr: end if changeEmbeddedObjectState = success end function 'returns true if the embedded object supports the state "expectedState", false otherwise function supportsEmbedState(xEmbeddedObject as object, expectedState as long) as boolean dim continue as boolean dim reachableStates() as long dim stateIndex as long continue = hasUnoInterfaces(xEmbeddedObject, "com.sun.star.embed.XEmbeddedObject") if (continue) then reachableStates = xEmbeddedObject.reachableStates stateIndex = lbound(reachableStates) while ((stateIndex <= ubound(reachableStates)) and continue) continue = (reachableStates(stateIndex) <> expectedState) stateIndex = stateIndex + 1 wend end if supportsEmbedState = (not continue) end function Regards, Thibault Vataire ----- Mail Original ----- De: "denis" <des...@gmail.com> À: dev@api.openoffice.org Envoyé: Lundi 7 Juin 2010 15:24:39 Objet: [api-dev] SpreadsheetView of embedded spreadsheet document Hi, I have a writer document with an embedded spreadsheet document inside. Now I would like to set the active (i.e. visible) sheet of that spreadsheet document. The question is, how do I get the SpreadsheetView when there's no controller available? ThisComponent.getEmbeddedObjects().getByName ("Objekt1") _ .getEmbeddedObject().getCurrentController() ' ==> NULL Is this possible at all if the writer document was opened hidden? Thanks, Denis --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org