Sub Main Dim oController as Object Dim oDrawDoc as Object Dim oSheet as Object Dim fila as Integer dim nDrawDocTotalPages as long fila = 0 oDrawDoc = ThisComponent oController = oDrawDoc.getCurrentController nDrawDocTotalPages = oDrawDoc.getDrawPages().getcount() '----- ' Use this line to create a NEW calc document ' and assign it to variable oDoc. oDoc = StarDesktop.loadComponentFromURL( "private:factory/scalc", "_blank", 0, Array() ) '----- ' Here are two ways to get access to one of the various sheets ' in the spreadsheet document. ' Note that these don't make the sheet *vislble*, they merely give ' access to the sheet's content within the program. oSheet = oDoc.getSheets().getByIndex( 0 ) ' get the zero'th sheet for I=0 to nDrawDocTotalPages - 1 ' oDrawPage = oDrawDoc.getCurrentController.getCurrentPage() oDrawPage = oDrawDoc.getDrawPages().getByIndex(I) pintarShapes(oDrawPage, oController, oSheet, fila) next ' End Sub Function GetDocumentController( oDoc As Object ) As Object Dim oCtrl As Object ' If the caller gave us the document model... If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then ' ...then get the controller from that. oCtrl = oDoc.getCurrentController() ' If the caller gave us a document controller... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then ' ...thanks! That's just what we wanted! oCtrl = oDoc ' If the caller gave us the document frame... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then oFrame = oDoc ' ...then get the controller from the frame. oCtrl = oFrame.getController() Else ' The caller did not give us what we expected! MsgBox( "GetDocController called with incorrect parameter." ) EndIf GetDocumentController() = oCtrl End Function Function pintarShapes(oDrawPage As Object, ByVal oController As Object, ByVal oSheet as Object, fila as Integer) ' Find out how many shapes are on current page. nNumShapes = oDrawPage.getCount () ' Iterate over each shape. For nShape = 0 To nNumShapes - 1 ' Get the shape. oShape = oDrawPage.getByIndex( nShape ) ' This is an example of how to check the NAME of the shape ' for something. ' If oShape.getName() = cShapeName Then ' ' Do something ' EndIf oController = GetDocumentController(oController) oController.select (oShape) ' If the shape is a control... If HasUnoInterfaces( oShape, "com.sun.star.drawing.XControlShape" ) Then ' Don't bother looking at ControlShape's. ' If the shape is a group of shapes... ElseIf HasUnoInterfaces( oShape, "com.sun.star.drawing.XShapes" ) Then pintarShapes(oShape, oController) ElseIf HasUnoInterfaces( oShape, "com.sun.star.text.XText" ) Then ooParagraphs = oShape.getText().createEnumeration() do while ooParagraphs.hasMoreElements OoPar = OoParagraphs.nextElement If OoPar.supportsService("com.sun.star.text.Paragraph") Then oTextPortionEnum = OoPar.createEnumeration() While oTextPortionEnum.hasMoreElements() oTextPortion = oTextPortionEnum.nextElement() if (oTextPortion.charWeight > 100) then ' MsgBox(oTextPortion.String) '----- ' Put some sales figures onto the sheet. oSheet.getCellByPosition( 0 , fila ).setString( oTextPortion.String ) fila = fila + 1 EndIf '' oTextPortion.CharHeight = oTextPortion.CharHeight - 2 Wend EndIf Loop oShape.CharHeight = oShape.CharHeight - 2 EndIf Next ' nShape End Function