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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Editing Text Documents 101<br />

Doc = StarDesktop.CurrentComponent<br />

Cursor = Doc.Text.createTextCursor<br />

Do<br />

Cursor.gotoEndOfWord(True)<br />

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

Proceed = Cursor.gotoNextSentence(False)<br />

Cursor.gotoNextWord(False)<br />

Loop While Proceed<br />

The example first creates a document object for the text that has just been opened. Then it<br />

iterates through the entire text, sentence by sentence, and highlights each of the first<br />

words and formats this in bold.<br />

Retrieving and Modifying Text Contents<br />

If a TextCursor contains a highlighted area, then this text is available by means of the<br />

String property of the TextCursor object. The following example uses the String property to<br />

display the first words of a sentence in a message box:<br />

Dim Doc As Object<br />

Dim Cursor As Object<br />

Dim Proceed As Boolean<br />

Doc = StarDesktop.CurrentComponent<br />

Cursor = Doc.Text.createTextCursor<br />

Do<br />

Cursor.gotoEndOfWord(True)<br />

MsgBox Cursor.String<br />

Proceed = Cursor.gotoNextSentence(False)<br />

Cursor.gotoNextWord(False)<br />

Loop While Proceed<br />

The first word of each sentence can be modified in the same way using the String property:<br />

Dim Doc As Object<br />

Dim Cursor As Object<br />

Dim Proceed As Boolean<br />

Doc = StarDesktop.CurrentComponent<br />

Cursor = Doc.Text.createTextCursor<br />

Do

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

Saved successfully!

Ooh no, something went wrong!