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 />

HoriJustify (enum)<br />

horizontal justification of the text (value from com.sun.star.table.CellHoriJustify)<br />

VertJustify (enum)<br />

vertical justification of the text (value from com.sun.star.table.CellVertJustify)<br />

Orientation (enum)<br />

orientation of text (value in accordance with com.sun.star.table.CellOrientation)<br />

IsTextWrapped (Boolean)<br />

permits automatic line breaks within the cell<br />

RotateAngle (Long)<br />

angle of rotation of text in hundredths of a degree<br />

The following example shows how you can "stack" the contents of a cell so that the individual characters are<br />

printed one under another in the top left corner of the cell. The characters are not rotated.<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 />

Cell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT<br />

Cell.VertJustify = com.sun.star.table.CellVertJustify.TOP<br />

Cell.Orientation = com.sun.star.table.CellOrientation.STACKED<br />

Number, Date and Text Format<br />

<strong>OpenOffice</strong>.<strong>org</strong> provides a whole range of predefined date and time formats. Each of these formats has an<br />

internal number that is used to assign the format to cells using the NumberFormat property. <strong>OpenOffice</strong>.<strong>org</strong><br />

provides the queryKey and addNew methods so that you can access existing number formats as well as create<br />

your own number formats. The methods are accessed through the following object call:<br />

NumberFormats = Doc.NumberFormats<br />

A format is specified using a format string that is structured in a similar way to the format function of<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic. However there is one major difference: whereas the command format expects English<br />

abbreviations and decimal points or characters as thousands separators, the country-specified abbreviations must<br />

be used for the structure of a command format for the NumberFormats object.<br />

The following example formats the B2 cell so that numbers are displayed with three decimal places and use<br />

commas as a thousands separator.<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim Cell As Object<br />

Dim NumberFormats As Object<br />

Dim NumberFormatString As String<br />

Dim NumberFormatId As Long<br />

Dim LocalSettings As New com.sun.star.lang.Locale<br />

Doc = ThisComponent<br />

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

Cell = Sheet.getCellByPosition(1,1)<br />

Cell.Value = 23400.3523565<br />

LocalSettings.Language = "en"<br />

LocalSettings.Country = "us"<br />

NumberFormats = Doc.NumberFormats<br />

NumberFormatString = "#,##0.000"<br />

NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)<br />

If NumberFormatId = -1 Then<br />

100 <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!