OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
More Than Just Text<br />
AnchorType (Enum)<br />
determines the anchor type of a TextContent object (default values in accordance with<br />
com.sun.star.text.TextContentAnchorType enumeration).<br />
AnchorTypes (sequence of Enum)<br />
enumeration of all AnchorTypes which support a special TextContent object.<br />
TextWrap (Enum)<br />
determines the text wrap type around a TextContent object (default values in accordance with<br />
com.sun.star.text.WrapTextMode enumeration).<br />
The TextContent objects also share some methods – in particular, those for creating, inserting and deleting<br />
objects.<br />
A new TextContent object is created using the createInstance method of the document object.<br />
An object is inserted using the insertTextContent method of the text object.<br />
TextContent objects are deleted using the removeTextContent method.<br />
You will find a range of examples which use these methods in the following sections.<br />
Tables<br />
The following example creates a table with the help of the createInstance method described previously.<br />
Dim Doc As Object<br />
Dim Table As Object<br />
Dim Cursor As Object<br />
Doc = ThisComponent<br />
Cursor = Doc.Text.createTextCursor()<br />
Table = Doc.createInstance("com.sun.star.text.TextTable")<br />
Table.initialize(5, 4)<br />
Doc.Text.insertTextContent(Cursor, Table, False)<br />
Once created, the table is set to the number of rows and columns requested using an initialize call and then<br />
inserted in the text document using insertTextContent.<br />
As can be seen in the example, the insertTextContent method expects not only the Content object to be<br />
inserted, but two other parameters:<br />
a Cursor object which determines the insert position<br />
a Boolean variable which specifies whether the Content object is to replace the current selection of the<br />
cursor (True value) or is to be inserted before the current selection in the text (False)<br />
Note – VBA : When creating and inserting tables in a text document, objects similar to those available in VBA<br />
are used in <strong>OpenOffice</strong>.<strong>org</strong> Basic: The document object and a TextCursor object in <strong>OpenOffice</strong>.<strong>org</strong> Basic, or<br />
the Range object as the VBA counterpart. Whereas the Document.Tables.Add method takes on the task of<br />
creating and setting the table in VBA, this is created in <strong>OpenOffice</strong>.<strong>org</strong> Basic in accordance with the previous<br />
example using createInstance, initialized, and inserted in the document through insertTextContent.<br />
The tables inserted in a text document can be determined using a simple loop. The method getTextTables()<br />
of the text document object is used for this purpose:<br />
Dim Doc As Object<br />
Dim TextTables As Object<br />
Dim Table As Object<br />
Dim I As Integer<br />
Doc = ThisComponent<br />
TextTables = Doc.getTextTables()<br />
For I = 0 to TextTables.count - 1<br />
Table = TextTables(I)<br />
' Editing table<br />
Next I<br />
82 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010