Documentation/How Tos/Calc: STYLE function
Applies a style (for example a colour) to a cell.
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.
- Another way to apply styles can be found at Format - Conditional Formating....
- There is no direct way to determine (in a formula) what formatting has been applied to a cell.
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) will return a zero length string which can be concatenated to an existing string without affecting it.
=IF(STYLE("Red"); ""; yourformula)
- where yourformula stands for some formula, displays the result of yourformula with a red background. This method might be useful if you cannot predict whether yourformula will return text or a number (for example with HLOOKUP).
The STYLE function is unique to Calc.