Documentation/How Tos/Calc: STYLE function

From Apache OpenOffice Wiki
< Documentation‎ | How Tos
Revision as of 09:36, 8 February 2008 by Drking (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


STYLE

Applies a style (for example a colour) to a cell.

Syntax:

STYLE(style; timesecs; finalstyle)

STYLE applies the initial style style to its cell for timesecs seconds, and thereafter applies the final style finalstyle. Both styles are given as text.
Styles are listed (and may be created) in the Format - Styles and Formatting menu.
The initial style is applied for timesecs seconds after the cell itself is recalculated. Please note that a manual recalculation (F9 key or Tools - Cell Contents - Recalculate) will not trigger the initial style.
timesecs and finalstyle may together be omitted; style is then applied permanently.
STYLE returns the numeric value 0, so it may be added on to an existing calculation in the cell without changing the result. See the examples below.


Example:

In these examples, it is assumed you have created a new style "Red" where the cell has a red background. "Default" is the default style already defined in Calc.

=3 + 5 + STYLE("Red"; 3; "Default")

displays 8 (the result of adding 3 and 5) with a red background for 3 seconds, and in the default style thereafter.

=SQRT(9) + STYLE("Red")

displays 3 (the square root of 9) permanently with a red background.

=A1 + STYLE(IF(A1>3;"Red";"Default"))

displays the numeric contents of cell A1, with a red background if A1 is greater than 3. Here the IF function returns the name of the style for STYLE to use (either "Red" or "Default"), depending on the value of cell A1.

=A1 + STYLE(IF(CURRENT()>3;"Red";"Default"))

also displays the numeric contents of cell A1, with a red background if A1 is greater than 3.

="Some text" & T(STYLE("Red"))

displays the text Some text with a red background. The STYLE function always returns 0, so T(0) function will return a zero length string which can be concatenated to an existing string without affecting it.

See also:

Spreadsheet functions

Issues:

The STYLE function is unique to Calc.

Personal tools