Re: Benutzerdefinierte Eigenschaften (OOo3.1)
Verfasst: Mo, 27.07.2009 11:35
Besorge Dir Andrew Pitonyaks Makro Dokument, da ist ein Beispiel drinne.
deutsches Forum rund um Apache OpenOffice und LibreOffice
http://www.oooforum.de/
Code: Alles auswählen
If userProps.getPropertySetInfo().hasByName( strVarName ) Then
print "vorhanden: " & strVarName
Else
userProps.removeProperty(strVarName)
userProps.addProperty(strVarName, ,aValue)
End If
Code: Alles auswählen
Sub Main
msgbox(SetDocProperty("myName", "viper"))
msgbox(GetDocProperty("myName"))
msgbox(SetDocProperty("myName", "bone"))
msgbox(GetDocProperty("myName"))
End Sub
Public Sub SetDocProperty(ByVal strVarName, ByVal aValue) as Boolean
Dim userProps As Object
Dim result as Boolean
result = false
On Error Goto ErrHandler
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = False then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertyContainer.html
userProps.addProperty(strVarName, ,aValue)
Else
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
userProps.setPropertyValue(strVarName, aValue)
End If
result = true
ExitFunc:
SetDocProperty = result
Exit sub
ErrHandler:
Goto ExitFunc
End Sub
Public Sub GetDocProperty(ByVal strVarName) As String
Dim userProps As Object
On Error Resume Next
' get UserDefined Properties
userProps = thisComponent.DocumentProperties.getUserDefinedProperties()
' Try to Remove; on Error Property doesen't exists yet
If userProps.getPropertySetInfo().hasPropertyByName(strVarName) = True then
' http://api.openoffice.org/docs/common/ref/com/sun/star/beans/XPropertySet.html
GetDocProperty = userProps.getPropertyValue(strVarName)
Else
GetDocProperty = ""
End If
End Sub