Document User Fields: XDocumentInfoSupplier


Document User Fields: XDocumentInfoSupplier

Each document contains four user fields. To access them manually, click File Properties and then choose the User Defined tab. This tab contains four text fields with user information. Use the interface com.sun.star.document.XDocumentInfoSupprierto retrieve and set these text fields. The object method getDocumentInfo() returns an object that supports the interface com.sun.star.document.XDocumentInfo (see Table 4 ).

Table 4: Object methods defined by the interface XDocumentlnfo.

Object Method

Description

GetUserFieldCount()

Number of available fields.

getUserFieldName(index)

Name of the specified field.

getUserFieldValue(index)

Value of the specified field.

setUserFieldName(index, name)

Set the name of the specified field.

setUserFieldValue(index, value)

Set the value of the specified field.

The macro in Listing 3 sets the value of a user field and then displays its value. Figure 2 shows the user-information fields in the current document.


Figure 2: The user-information fields in the current document.
Listing 3: GetUserlnfoFields is found in the Generic module in this chapter's source code files as SC12.sxw.
start example
 Sub GetUserlnfoFields   Dim vDocInfo  'Document Information Object   Dim s$        'General string to print   Dim i%        'Index variable   vDocInfo = ThisComponent.getDocumentInfo()   vDocInfo.setUserFieldValue(1, "My special user value")   For i% = 0 To vDocInfo().getUserFieldCount()-1     s$ = s$ & vDocInfo.getUserFieldName(i) & " = " &_          CStr(vDocInfo.getUserFieldValue(i)) & CHR$(10)   Next   MsgBox s$, 0, "Info Fields" End Sub 
end example
 



OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net