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.
Cell = Sheet.getCellByPosition(0, 0)<br />
Cell.String = "Test"<br />
The Structure of Spreadsheets<br />
In addition to numerical coordinates, each cell in a sheet has a name, for example, the top left cell (0,0) of a<br />
spreadsheet is called A1. The letter A stands for the column and the number 1 for the row. It is important that the<br />
name and position of a cell are not confused because row counting for names begins with 1 but the counting for<br />
position begins with 0.<br />
If the position of the cell is fixed, it is more clear to use the following code:<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.getCellRangeByName("A1")<br />
Cell.String = "Test"<br />
The above code also works with a named cell.<br />
In <strong>OpenOffice</strong>.<strong>org</strong>, a table cell can be empty or contain text, numbers, or formulas. The cell type is not<br />
determined by the content that is saved in the cell, but rather the object property which was used for its entry.<br />
Numbers can be inserted and called up with the Value property, text with the String property, and formulas<br />
with the Formula property.<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(0, 0)<br />
Cell.Value = 100<br />
Cell = Sheet.getCellByPosition(0, 1)<br />
Cell.String = "Test"<br />
Cell = Sheet.getCellByPosition(0, 2)<br />
Cell.Formula = "=A1"<br />
The example inserts one number, one text, and one formula in the fields A1 to A3.<br />
Note – StarOffice 5 : The Value, String, and Formula properties supersede the old PutCell method of<br />
StarOffice 5 for setting the values of a table cell.<br />
<strong>OpenOffice</strong>.<strong>org</strong> treats cell content that is entered using the String property as text, even if the content is a<br />
number. Numbers are left-aligned in the cell instead of right-aligned. You should also note the difference between<br />
text and numbers when you use formulas:<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(0, 0)<br />
Cell.Value = 100<br />
Cell = Sheet.getCellByPosition(0, 1)<br />
Cell.String = 1000<br />
Cell = Sheet.getCellByPosition(0, 2)<br />
Cell.Formula = "=A1+A2"<br />
MsgBox Cell.Value<br />
Although cell A1 contains the value 100 and cell A2 contains the value 1000, the A1+A2 formula returns the<br />
value 100. This is because the contents of cell A2 were entered as a string and not as a number.<br />
To check if the contents of a cell contains a number or a string, use the Type property:<br />
Chapter 7 · Spreadsheet Documents 95