OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - 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.
More Than Just Text 108<br />
Tables<br />
The following example creates a table with the help of the createInstance method described<br />
previously.<br />
Dim Doc As Object<br />
Dim Table As Object<br />
Dim Cursor As Object<br />
Doc = StarDesktop.CurrentComponent<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<br />
initialize call and then inserted in the text document using insertTextContent.<br />
As can be seen in the example, the insertTextContent method expects not only the Content<br />
object to be 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<br />
selection of the cursor (True value) or is to be inserted before the current selection in the<br />
text (False)<br />
When creating and inserting tables in a text document, objects similar to those available in VBA are<br />
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<br />
of creating and setting the table in VBA, this is created in <strong>OpenOffice</strong>.<strong>org</strong> Basic in accordance with the<br />
previous example using createInstance, initialized, and inserted in the document through<br />
insertTextContent.<br />
The tables inserted in a text document can be determined using a simple loop. The method<br />
getTextTables() 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 = StarDesktop.CurrentComponent<br />
TextTables = Doc.getTextTables()<br />
For I = 0 to TextTables.count - 1<br />
Table = TextTables(I)<br />
' Editing table