21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

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 116<br />

The example creates a text frame, inserts this in the current document and opens a<br />

TextCursor for the text frame. This cursor is used to set the frame font to bold type and to<br />

set the paragraph orientation to centered. The text frame is finally assigned the “This is a<br />

small test!” string.<br />

Text Fields<br />

Text fields are TextContent objects because they provide additional logic extending beyond<br />

pure text. Text fields can be inserted in a text document using the same methods as those<br />

used for other TextContent objects:<br />

Dim Doc As Object<br />

Dim DateTimeField As Object<br />

Dim Cursor As Object<br />

Doc = StarDesktop.CurrentComponent<br />

Cursor = Doc.Text.createTextCursor()<br />

DateTimeField =<br />

Doc.createInstance("com.sun.star.text.textfield.DateTime")<br />

DateTimeField.IsFixed = False<br />

DateTimeField.IsDate = True<br />

Doc.Text.insertTextContent(Cursor, DateTimeField, False)<br />

The example inserts a text field with the current date at the start of the current text<br />

document. The True value of the IsDate property results in only the date and not time being<br />

displayed. The False value for IsFixed ensures that the date is automatically updated when<br />

the document is opened.<br />

While the type of a field in VBA is specified by a parameter of the Document.Fields.Add method, the<br />

name of the service that is responsible for the field type in question defines it in <strong>OpenOffice</strong>.<strong>org</strong> Basic.<br />

In the past, text fields were accessed using a whole range of methods that <strong>OpenOffice</strong>.<strong>org</strong><br />

made available in the old Selection object (for example InsertField, DeleteUserField,<br />

SetCurField).<br />

In <strong>OpenOffice</strong>.<strong>org</strong> 2.x, the fields are administered using an object-oriented concept. To<br />

create a text field, a text field of the type required should first be created and initialized<br />

using the properties required. The text field is then inserted in the document using the<br />

insertTextContent method. A corresponding source text can be seen in the previous<br />

example. The most important field types and their properties are described in the following<br />

sections.<br />

In addition to inserting text fields, searching a document for the fields can also be an<br />

important task. The following example shows how all text fields of a text document can be<br />

traversed in a loop and checked for their relevant type.<br />

Dim Doc As Object<br />

Dim TextFieldEnum As Object

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!