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

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

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

VARP<br />

variance based on the total population<br />

Editing Spreadsheet Documents<br />

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

Dim Doc As Object<br />

Dim Sheet As Object<br />

Dim CellRange As Object<br />

Doc = ThisComponent<br />

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

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

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

Warning – Functions VAR, VARP, STDVERP return an incorrect value when applied to a properly defined<br />

range. See Issue 22625 .<br />

Deleting Cell Contents<br />

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

specific type of content from a cell range.<br />

The following example removes all the strings and the direct formatting information from 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 = ThisComponent<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 com.sun.star.sheet.CellFlags constants list. This list<br />

provides the following elements:<br />

VALUE<br />

DATETIME<br />

STRING<br />

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

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

strings<br />

ANNOTATION<br />

FORMULA<br />

HARDATTR<br />

STYLES<br />

OBJECTS<br />

comments that are linked to cells<br />

formulas<br />

direct formatting of cells<br />

indirect formatting<br />

drawing objects that are connected to cells<br />

Chapter 7 · Spreadsheet Documents 109

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

Saved successfully!

Ooh no, something went wrong!