21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Formatting Spreadsheet Documents 137<br />

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

function of <strong>OpenOffice</strong>.<strong>org</strong> Basic. However there is one major difference: whereas the<br />

command format expects English abbreviations and decimal points or characters as<br />

thousands separators, the country-specified abbreviations must be used for the structure of<br />

a command format for the NumberFormats object.<br />

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

decimal places and use 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 = StarDesktop.CurrentComponent<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,<br />

LocalSettings, True)<br />

If NumberFormatId = -1 Then<br />

NumberFormatId = NumberFormats.addNew(NumberFormatString,<br />

LocalSettings)<br />

End If<br />

MsgBox NumberFormatId<br />

Cell.NumberFormat = NumberFormatId<br />

The Format Cells dialog in <strong>OpenOffice</strong>.<strong>org</strong> Calc provides an overview of the different<br />

formatting options for cells.

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

Saved successfully!

Ooh no, something went wrong!