von komma4 » Mo, 19.07.2010 14:58
Wenn Du die Dokumente mit Basic öffnen würdest... hättest Du gleich auch die Objektreferenz.
Wenn nicht, dann hilft es Dir die geöffneten Komponenten durchzugehen, mit dem Code von DannyB -dem sogenannten ComponentWalker- solltest Du weiter kommen...
Code: Alles auswählen
REM http://www.oooforum.org/forum/viewtopic.phtml?t=3712
REM DannyB 2003-11-06
Sub Main
oComponents = StarDesktop.getComponents()
' Show me how many total components are open?
nCount = 0
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
nCount = nCount + 1
Loop
Print "There are "; nCount; " components open."
' Walk through the components looking for documents of a specific type.
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
' See if component is a document.
' Any com.sun.star.document.OfficeDocument supports XModel.
' Of course, we could have just checked for the service OfficeDocument,
' see the Drawing example below for how to check for a service.
If HasUnoInterfaces( oComponent, "com.sun.star.frame.XModel" ) Then
' It will have this particular interface if it is a spreadsheet document.
If HasUnoInterfaces( oComponent, "com.sun.star.sheet.XSpreadsheetDocument" ) Then
' Notify me if we found a spreadsheet document has a sheet named "Sheet2",
' and cell C2 of that sheet contains the text "Meow Mix".
oSheets = oComponent.getSheets()
If oSheets.hasByName( "Sheet2" ) Then
oSheet = oSheets.getByName( "Sheet2" )
If oSheet.getCellByPosition( 2, 1 ).getFormula() = "Meow Mix" Then
MsgBox( "Found the componenet, which is a spreadsheet, which has a sheet names Sheet2, whose cell C2 contains Meow Mix." )
EndIf
EndIf ' If it has Sheet2
EndIf ' If it is a spreadsheet
' If the component is Untitled, that is, has not been saved, then notify me.
If Not oComponent.hasLocation() Then
MsgBox( "Untitled component found." )
EndIf ' if it is untitled.
' If the document is saved, and is C:\MYDOC.SXC
If oComponent.hasLocation() Then
cURL = oComponent.getLocation()
cFile = ConvertFromURL( cURL )
msgbox cFile
REM If UCase( cFile ) = "C:\MYDOC.SXC" Then
If cFile = "/home/zwinni/findeDok.odt" Then
MsgBox( "Found the document C:\MYDOC.SXC" )
EndIf
EndIf
' It will have this particular SERVICE if it is a drawing document.
If oComponent.SupportsService( "com.sun.star.drawing.DrawingDocument" ) Then
' Notify me if we found a drawing document that has a shape named "Apple Jacks"
' on its second page.
oDrawPages = oComponent.getDrawPages()
if oDrawPages.getCount() >= 2 Then
oDrawPage = oDrawPages.getByIndex( 1 )
For nShape = 0 To oDrawPage.getCount() - 1
oShape = oDrawPage.getByIndex( i )
If oShape.getName() = "Apple Jacks" Then
MsgBox( "Found the component, which is a drawing, which has a shape named Apple Jacks on its second page." )
EndIf
Next
EndIf ' If it has 2 or more pages
EndIf ' If it is a drawing
EndIf ' if it has XModel (which probably means it is an OfficeDocument)
Loop
End Sub
Viel Erfolg!
Wenn Du die Dokumente mit Basic öffnen würdest... hättest Du gleich auch die Objektreferenz.
Wenn nicht, dann hilft es Dir die geöffneten Komponenten durchzugehen, mit dem Code von DannyB -dem sogenannten ComponentWalker- solltest Du weiter kommen...
[code] REM http://www.oooforum.org/forum/viewtopic.phtml?t=3712
REM DannyB 2003-11-06
Sub Main
oComponents = StarDesktop.getComponents()
' Show me how many total components are open?
nCount = 0
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
nCount = nCount + 1
Loop
Print "There are "; nCount; " components open."
' Walk through the components looking for documents of a specific type.
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
' See if component is a document.
' Any com.sun.star.document.OfficeDocument supports XModel.
' Of course, we could have just checked for the service OfficeDocument,
' see the Drawing example below for how to check for a service.
If HasUnoInterfaces( oComponent, "com.sun.star.frame.XModel" ) Then
' It will have this particular interface if it is a spreadsheet document.
If HasUnoInterfaces( oComponent, "com.sun.star.sheet.XSpreadsheetDocument" ) Then
' Notify me if we found a spreadsheet document has a sheet named "Sheet2",
' and cell C2 of that sheet contains the text "Meow Mix".
oSheets = oComponent.getSheets()
If oSheets.hasByName( "Sheet2" ) Then
oSheet = oSheets.getByName( "Sheet2" )
If oSheet.getCellByPosition( 2, 1 ).getFormula() = "Meow Mix" Then
MsgBox( "Found the componenet, which is a spreadsheet, which has a sheet names Sheet2, whose cell C2 contains Meow Mix." )
EndIf
EndIf ' If it has Sheet2
EndIf ' If it is a spreadsheet
' If the component is Untitled, that is, has not been saved, then notify me.
If Not oComponent.hasLocation() Then
MsgBox( "Untitled component found." )
EndIf ' if it is untitled.
' If the document is saved, and is C:\MYDOC.SXC
If oComponent.hasLocation() Then
cURL = oComponent.getLocation()
cFile = ConvertFromURL( cURL )
msgbox cFile
REM If UCase( cFile ) = "C:\MYDOC.SXC" Then
If cFile = "/home/zwinni/findeDok.odt" Then
MsgBox( "Found the document C:\MYDOC.SXC" )
EndIf
EndIf
' It will have this particular SERVICE if it is a drawing document.
If oComponent.SupportsService( "com.sun.star.drawing.DrawingDocument" ) Then
' Notify me if we found a drawing document that has a shape named "Apple Jacks"
' on its second page.
oDrawPages = oComponent.getDrawPages()
if oDrawPages.getCount() >= 2 Then
oDrawPage = oDrawPages.getByIndex( 1 )
For nShape = 0 To oDrawPage.getCount() - 1
oShape = oDrawPage.getByIndex( i )
If oShape.getName() = "Apple Jacks" Then
MsgBox( "Found the component, which is a drawing, which has a shape named Apple Jacks on its second page." )
EndIf
Next
EndIf ' If it has 2 or more pages
EndIf ' If it is a drawing
EndIf ' if it has XModel (which probably means it is an OfficeDocument)
Loop
End Sub
[/code]
Viel Erfolg!