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.

Editing Text Documents 105<br />

Found = Doc.findFirst (SearchDesc)<br />

Do While Found<br />

Found.CharWeight = com.sun.star.awt.FontWeight.BOLD<br />

Found = Doc.findNext( Found.End, Search)<br />

Loop<br />

The basic idea of search and replace in <strong>OpenOffice</strong>.<strong>org</strong> is comparable to that used in VBA. Both<br />

interfaces provide you with an object, through which the properties for searching and replacing can be<br />

defined. This object is then applied to the required text area in order to perform the action. Whereas the<br />

responsible auxiliary object in VBA can be reached through the Find property of the Range object, in<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic it is created by the createSearchDescriptor or createReplaceDescriptor call of the<br />

document object. Even the search properties and methods available differ.<br />

As in the old API from <strong>OpenOffice</strong>.<strong>org</strong>, searching and replacing text in the new API is also<br />

performed using the document object. Whereas previously there was an object called<br />

SearchSettings especially for defining the search options, in the new object searches are<br />

now performed using a SearchDescriptor or ReplaceDescriptor object for automatically<br />

replacing text. These objects cover not only the options, but also the current search text<br />

and, if necessary, the associated text replacement. The descriptor objects are created using<br />

the document object, completed in accordance with the relevant requests, and then<br />

transferred back to the document object as parameters for the search methods.<br />

Replacing Text Portions<br />

Just as with the search function, the replacement function from <strong>OpenOffice</strong>.<strong>org</strong> is also<br />

available in <strong>OpenOffice</strong>.<strong>org</strong> Basic. The two functions are handled identically. A special<br />

object which records the parameters for the process is also first needed for a replacement<br />

process. It is called a ReplaceDescriptor and supports the<br />

com.sun.star.util.ReplaceDescriptor<br />

service. All the properties of the SearchDescriptor described in the previous paragraph are<br />

also supported by ReplaceDescriptor. For example, during a replacement process, case<br />

sensitivity can also be activated and deactivated, and similarity searches can be performed.<br />

The following example demonstrates the use of ReplaceDescriptors for a search within a<br />

<strong>OpenOffice</strong>.<strong>org</strong> document.<br />

Dim I As Long<br />

Dim Doc As Object<br />

Dim Replace As Object<br />

Dim BritishWords(5) As String<br />

Dim USWords(5) As String<br />

BritishWords() = Array("colour", "neighbour", "centre", "behaviour", _<br />

"metre", "through")<br />

USWords() = Array("color", "neighbor", "center", "behavior", _

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

Saved successfully!

Ooh no, something went wrong!