21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - 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.

The Structure of Spreadsheets<br />

The following example activates the automatic height optimization for the first five rows in the sheet and makes<br />

the second column invisible.<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim Row As Object<br />

Dim Col As Object<br />

Dim I As Integer<br />

Doc = ThisComponent<br />

Sheet = Doc.Sheets(0)<br />

For I = 0 To 4<br />

Row = Sheet.Rows(I)<br />

Row.OptimalHeight = True<br />

Next I<br />

Col = Sheet.Columns(1)<br />

Col.IsVisible = False<br />

Note – The Rows and Columns lists can be accessed through an index in <strong>OpenOffice</strong>.<strong>org</strong> Basic. The real API<br />

call is : Sheet.getColumns.getByIndex(1)<br />

Note – VBA : Unlike in VBA, the first column has the index 0 and not the index 1.<br />

Inserting and Deleting Rows and Columns<br />

The Rows and Columns objects of a sheet can access existing rows and columns as well as insert and delete them.<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim NewColumn As Object<br />

Doc = ThisComponent<br />

Sheet = Doc.Sheets(0)<br />

Sheet.Columns.insertByIndex(3, 1)<br />

Sheet.Columns.removeByIndex(5, 1)<br />

This example uses the insertByIndex method to insert a new column into the fourth column position in the<br />

sheet (index 3 - numbering starts at 0). The second parameter specifies the number of columns to be inserted (in<br />

this example: one).<br />

The removeByIndex method deletes the sixth column (index 5). Again, the second parameter specifies the<br />

number of columns that you want to delete.<br />

The methods for inserting and deleting rows use the Rows object function in the same way as the methods shown<br />

for editing columns using the Columns object.<br />

Cells and Ranges<br />

A spreadsheet consists of a two-dimensional list containing cells. Each cell is defined by its X and Y-position with<br />

respect to the top left cell which has the position (0,0).<br />

Addressing and Editing Individual Cells<br />

The following example creates an object that references the top left cell and inserts a text in the cell:<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim Cell As Object<br />

Doc = ThisComponent<br />

Sheet = Doc.Sheets(0)<br />

94 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

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

Saved successfully!

Ooh no, something went wrong!