Documentation/Calc Functions/STYLE

    From The Document Foundation Wiki
    Other languages:


    Function name:

    STYLE

    Category:

    Spreadsheet

    Summary:

    Applies a style to the cell containing the function call and, optionally, applies a second style to that cell after a time delay. STYLE can be helpful when you need to use a formula to dynamically change the formatting applied to a cell.

    The STYLE function should not be used without compelling reason. Its purpose is the use with asynchronous Add-In functions to visually notify about the availability of a result. In almost all other cases, using conditional formatting is a better choice.

    Syntax:

    STYLE(Style[; Time[; Style2]])

    Returns:

    Returns the value 0 (zero), allowing you to add the STYLE function call to other components of a formula without changing the overall value output from the formula.

    Arguments:

    Style is a string in quotation marks, or a reference to a cell containing that string, that is the name of a cell style to be (initially) assigned to the cell. If the string does not match the name of any defined cell style, the Default cell style is applied instead.

    Time is a positive real number, or a reference to a cell containing that number, that is the delay in seconds before applying the Style2 cell style. If this argument is omitted, the default value of 0 (zero) is assumed.

    Style2 is a string in quotation marks, or a reference to a cell containing that string, that is the name of a cell style to be applied to the cell after the specified delay Time has passed. If a delay Time is specified and the Style2 argument is omitted, the cell will revert to the Default cell style after the delay time.

    • If Time is a negative value, STYLE resets the value to 0. No error is reported in this circumstance.
    • If Time is set or reset to 0, the initially applied style is not changed and Style2 is never applied.

    Additional details:

    • Style switching through the STYLE function occurs when:
    • The function call is first entered in a cell.
    • After selecting Data ▸ Calculate ▸ Recalculate Hard, all STYLE function calls are reset.
    • After selecting Data ▸ Calculate ▸ Recalculate, the STYLE function call in the selected cell is reset.
    • STYLE is especially useful when used in conjunction with the CURRENT function to apply colors, fonts, or other formatting to a cell depending on its value. For example, consider the formula =(($A$1*$A$2)/$A$3) + STYLE(IF(CURRENT()>3; "Good"; "Bad")). This formula calculates the value of ($A$1*$A$2)/$A$3. If the result of this calculation is greater than 3, then that result is displayed in the formula cell using the Good cell style. Otherwise, the result is displayed in the formula cell using the Bad cell style.
    • There is no direct way in a formula to determine what formatting has been applied to a cell.

    Examples:

    Data for examples
    A B C
    1 4 Warning
    2 3 6 60.0
    3 2 7 Default
    Formula Description Returns
    =STYLE("Footnote") Returns 0 (zero) and formats the formula cell with the Footnote cell style. 0
    =STYLE(C1; C2; C3)

    Returns 0 (zero) and formats the formula cell for 60 seconds using the Warning cell style. After 60 seconds, the Default cell style is applied to the cell.

    0
    =SQRT(49) + STYLE("Neutral") Displays the square root of 49 in the Neutral cell style. 7
    =PI()*POWER(3; 2) + STYLE("Result"; 5; "Default") Displays π×32 (28.2743338823081) in the Result cell style for 5 seconds, and in the Default cell style thereafter. 28.2743...
    ="Text"&T(STYLE("Error"))

    STYLE("Error") applies the Error cell style to the formula cell and returns 0 (zero). T(0) converts the value 0 to an empty string (ensuring that 0 is not displayed). This is (notionally) appended to the string "Text".

    Text
    =B2+B3 + STYLE( IF( CURRENT()>10; "Bad"; "Good"))

    Returns the result of B2+B3, since the STYLE function always returns the value 0 (zero). However, the returned value will be displayed using the cell style named Bad if it is greater than 10, and using the cell style named Good otherwise.

    13

    Related LibreOffice functions:

    CELL

    CURRENT

    IF

    INFO

    N

    T

    TEXT

    VALUE

    ODF standard:

    None. See instead ORG.OPENOFFICE.STYLE

    Related (or similar) Excel functions:

    None.