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.
Editing Text Documents<br />
Retrieving and Modifying Text Contents<br />
If a TextCursor contains a highlighted area, then this text is available by means of the String property of the<br />
TextCursor object. The following example uses the String property to display the first words of a sentence in a<br />
message box:<br />
Dim Doc As Object<br />
Dim Cursor As Object<br />
Dim Proceed As Boolean<br />
Doc = ThisComponent<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 = ThisComponent<br />
Cursor = Doc.Text.createTextCursor<br />
Do<br />
Cursor.gotoEndOfWord(True)<br />
Cursor.String = "Ups"<br />
Proceed = Cursor.gotoNextSentence(False)<br />
Cursor.gotoNextWord(False)<br />
Loop While Proceed<br />
If the TextCursor contains a highlighted area, an assignment to the String property replaces this with the new<br />
text. If there is no highlighted area, the text is inserted at the present TextCursor position.<br />
Inserting Control Codes<br />
In some situations, it is not the actual text of a document, but rather its structure that needs modifying.<br />
<strong>OpenOffice</strong>.<strong>org</strong> provides control codes for this purpose. These are inserted in the text and influence its structure.<br />
The control codes are defined in the com.sun.star.text.ControlCharacter group of constants. The following<br />
control codes are available in <strong>OpenOffice</strong>.<strong>org</strong>:<br />
PARAGRAPH_BREAK<br />
paragraph break.<br />
LINE_BREAK<br />
line break within a paragraph.<br />
SOFT_HYPHEN<br />
possible point for syllabification.<br />
HARD_HYPHEN<br />
obligatory point for syllabification.<br />
HARD_SPACE<br />
protected space that is not spread out or compressed in justified text.<br />
To insert the control codes, you need not only the cursor but also the associated text document objects. The<br />
following example inserts a paragraph after the 20th character of a text:<br />
Dim Doc As Object<br />
Dim Cursor As Object<br />
Dim Proceed As Boolean<br />
Doc = ThisComponent<br />
Cursor = Doc.Text.createTextCursor<br />
Cursor.goRight(20, False)<br />
78 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010