OO-Snippets: traverse placeholders (unordered)

Commons

Keywordstraverse, placeholder, textfield, field, hint, getTextFields, enumeration
LanguageOOBasic
ApplicationWriter
AuthorsChristoph Lutz (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow do I traverse all placeholders in a document

a placeholder is a special textfield which is usefull as a placeholder for content evaluated by a macro

Answer

ThisComponent.getTextFields.createEnumeration provides a an enumeration of all fields. Use this enumeration to get all fields of type "JumpEdit" which represent placeholders. Note that the enumeration does NOT provide the fields in order of occurence in the document!

Code-Snippet-Listing (snippet-source)

Sub traversePlaceholders
  Dim vEnum as Variant
  Dim s as String
  vEnum = ThisComponent.getTextFields.createEnumeration
  REM Note: the enumeration is not sorted in the correct order of occurance!
  While vEnum.hasMoreElements()
    Dim vTextField as Variant
    vTextField = vEnum.nextElement
    REM This traverses all text-fields, but we only want placeholders.
    REM Placeholders are fields of type "JumpEdit"
    If vTextField.supportsService("com.sun.star.text.TextField.JumpEdit") Then
      Dim sName as String
      Dim sHint as String
      sName = vTextField.getPropertyValue("PlaceHolder")
      sHint = vTextField.getPropertyValue("Hint")
      s = s & sName & CHR$(10)
    End If
  Wend
  MsgBox s, 0, "Placeholders"
End Sub

Changelog

DateUserModification
2005-05-27CLInitial version

and