OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
More Than Just Text<br />
of the type required should first be created and initialized using the properties required. The text field is then<br />
inserted in the document using the insertTextContent method. A corresponding source text can be seen in<br />
the previous example. The most important field types and their properties are described in the following sections.<br />
In addition to inserting text fields, searching a document for the fields can also be an important task. The<br />
following example shows how all text fields of a text document can be traversed in a loop and checked for their<br />
relevant type.<br />
Dim Doc As Object<br />
Dim TextFieldEnum As Object<br />
Dim TextField As Object<br />
Dim I As Integer<br />
Doc = ThisComponent<br />
TextFieldEnum = Doc.getTextFields.createEnumeration<br />
While TextFieldEnum.hasMoreElements()<br />
Wend<br />
TextField = TextFieldEnum.nextElement()<br />
If TextField.supportsService("com.sun.star.text.textfield.DateTime") Then<br />
MsgBox "Date/time"<br />
ElseIf TextField.supportsService("com.sun.star.text.textfield.Annotation") Then<br />
MsgBox "Annotation"<br />
Else<br />
MsgBox "unknown"<br />
End If<br />
The starting point for establishing the text fields present is the TextFields list of the document object. The<br />
example creates an Enumeration object on the basis of this list, with which all text fields can be queried in turn<br />
in a loop. The text fields found are checked for the service supported using the supportsService method. If<br />
the field proves to be a date/time field or an annotation, then the corresponding field type is displayed in an<br />
information box. If on the other hand, the example encounters another field, then it displays the information<br />
“unknown”.<br />
Below, you will find a list of the most important text fields and their associated properties. A complete list of all<br />
text fields is provided in the API reference in the com.sun.star.text.textfield module. (When listing the<br />
service name of a text field, uppercase and lowercase characters should be used in <strong>OpenOffice</strong>.<strong>org</strong> Basic, as in the<br />
previous example.)<br />
Number of Pages, Words and Characters<br />
The text fields<br />
com.sun.star.text.textfield.PageCount<br />
com.sun.star.text.textfield.WordCount<br />
com.sun.star.text.textfield.CharacterCount<br />
return the number of pages, words, or characters of a text. They support the following property:<br />
NumberingType (const)<br />
numbering format (guidelines in accordance with constants from com.sun.star.style.NumberingType).<br />
Current Page<br />
The number of the current page can be inserted in a document using the com.sun.star.text.textfield.PageNumber<br />
text field. The following properties can be specified:<br />
NumberingType (const)<br />
number format (guidelines in accordance with constants from com.sun.star.style.NumberingType).<br />
Offset (short)<br />
offset added to the number of pages (negative specification also possible).<br />
88 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010