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.
The Structure of Spreadsheets<br />
Dim Doc As Object<br />
Dim Sheet As Object<br />
Dim Cell As Object<br />
Doc = ThisComponent<br />
Sheet = Doc.Sheets(0)<br />
Cell = Sheet.getCellByPosition(1,1)<br />
Cell.Value = 1000<br />
Select Case Cell.Type<br />
Case com.sun.star.table.CellContentType.EMPTY<br />
MsgBox "Content: Empty"<br />
Case com.sun.star.table.CellContentType.VALUE<br />
MsgBox "Content: Value"<br />
Case com.sun.star.table.CellContentType.TEXT<br />
MsgBox "Content: Text"<br />
Case com.sun.star.table.CellContentType.FORMULA<br />
MsgBox "Content: Formula"<br />
End Select<br />
The Cell.Type property returns a value for the com.sun.star.table.CellContentType enumeration which<br />
identifies the contents type of a cell. The possible values are:<br />
EMPTY<br />
VALUE<br />
TEXT<br />
FORMULA<br />
no value<br />
number<br />
strings<br />
formula<br />
Inserting, Deleting, Copying and Moving Cells<br />
In addition to directly modifying cell content, <strong>OpenOffice</strong>.<strong>org</strong> Calc also provides an interface that allows you to<br />
insert, delete, copy, or merge cells. The interface (com.sun.star.sheet.XRangeMovement) is available through the<br />
spreadsheet object and provides four methods for modifying cell content.<br />
The insertCell method is used to insert cells into a sheet.<br />
Dim Doc As Object<br />
Dim Sheet As Object<br />
Dim CellRangeAddress As New com.sun.star.table.CellRangeAddress<br />
Doc = ThisComponent<br />
Sheet = Doc.Sheets(0)<br />
CellRangeAddress.Sheet = 0<br />
CellRangeAddress.StartColumn = 1<br />
CellRangeAddress.StartRow = 1<br />
CellRangeAddress.EndColumn = 2<br />
CellRangeAddress.EndRow = 2<br />
Sheet.insertCells(CellRangeAddress, com.sun.star.sheet.CellInsertMode.DOWN)<br />
This example inserts a cells range that is two rows by two columns in size into the second column and row (each<br />
bear the number 1) of the first sheet (number 0) in the spreadsheet. Any existing values in the specified cell range<br />
are moved below the range.<br />
To define the cell range that you want to insert, use the com.sun.star.table.CellRangeAddress structure. The<br />
following values are included in this structure:<br />
Sheet (short)<br />
number of the sheet (numbering begins with 0).<br />
96 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010