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.

Editing Spreadsheet Documents 150<br />

variance based on the total population<br />

The following example computes the average value of the A1:C3 range and prints the result<br />

in a message box:<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim CellRange As Object<br />

Doc = StarDesktop.CurrentComponent<br />

Sheet = Doc.Sheets.getByName("Sheet 1")<br />

CellRange = Sheet.getCellRangeByName("A1:C3")<br />

MsgBox<br />

CellRange.computeFunction(com.sun.star.sheet.GeneralFunction.AVERAGE)<br />

Deleting Cell Contents<br />

The clearContents method simplifies the process of deleting cell contents and cell ranges in<br />

that it deletes one specific type of content from a cell range.<br />

The following example removes all the strings and the direct formatting information from<br />

the B2:C3 range.<br />

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim CellRange As Object<br />

Dim Flags As Long<br />

Doc = StarDesktop.CurrentComponent<br />

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

CellRange = Sheet.getCellRangeByName("B2:C3")<br />

Flags = com.sun.star.sheet.CellFlags.STRING + _<br />

com.sun.star.sheet.CellFlags.HARDATTR<br />

CellRange.clearContents(Flags)<br />

The flags specified in clearContents come from the<br />

com.sun.star.sheet.CellFlags<br />

constants list. This list provides the following elements:<br />

VALUE<br />

numerical values that are not formatted as date or time<br />

DATETIME

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

Saved successfully!

Ooh no, something went wrong!