Learn R Programming

openxlsx2 (version 0.4.1)

wb_add_conditional_formatting: Add conditional formatting to cells

Description

Add conditional formatting to cells

Usage

wb_add_conditional_formatting(
  wb,
  sheet = current_sheet(),
  cols,
  rows,
  rule = NULL,
  style = NULL,
  type = c("expression", "colorScale", "dataBar", "duplicatedValues", "containsText",
    "notContainsText", "beginsWith", "endsWith", "between", "topN", "bottomN"),
  params = list(showValue = TRUE, gradient = TRUE, border = TRUE, percent = FALSE, rank =
    5L)
)

wb_conditional_formatting( wb, sheet, cols, rows, rule = NULL, style = NULL, type = c("expression", "colorScale", "dataBar", "duplicatedValues", "containsText", "notContainsText", "beginsWith", "endsWith", "between", "topN", "bottomN"), ... )

Arguments

wb

A workbook object

sheet

A name or index of a worksheet

cols

Columns to apply conditional formatting to

rows

Rows to apply conditional formatting to

rule

The condition under which to apply the formatting. See examples.

style

A style to apply to those cells that satisfy the rule. Default is 'font_color = "FF9C0006"' and 'bgFill = "FFFFC7CE"'

type

The type of conditional formatting rule to apply.

params

Additional parameters passed. See Details for more

...

passed to params

Details

See Examples.

Conditional formatting types accept different parameters. Unless noted, unlisted parameters are ignored.

expression

[style]
A Style object

[rule]
An Excel expression (as a character). Valid operators are: <, <=, >, >=, ==, !=

colorScale

[style]
A character vector of valid colors with length 2 or 3

[rule]
NULL or a character vector of valid colors of equal length to styles

dataBar

[style]
A character vector of valid colors with length 2 or 3

[rule]
A numeric vector specifying the range of the databar colors. Must be equal length to style

[params$showValue]
If FALSE the cell value is hidden. Default TRUE

[params$gradient]
If FALSE colour gradient is removed. Default TRUE

[params$border]
If FALSE the border around the database is hidden. Default TRUE

duplicated

[style]
A Style object

contains

[style]
A Style object

[rule]
The text to look for within cells

between

[style]
A Style object.

[rule]
A numeric vector of length 2 specifying lower and upper bound (Inclusive)

topN

[style]
A Style object

[params$rank]
A numeric vector of length 1 indicating number of highest values. Default 5L

[params$percent] If TRUE uses percentage

bottomN

[style]
A Style object

[params$rank]
A numeric vector of length 1 indicating number of lowest values. Default 5L

[params$percent]
If TRUE uses percentage

Examples

Run this code
wb <- wb_workbook()
wb$add_worksheet("a")
wb$add_data("a", 1:4, colNames = FALSE)
wb$add_conditional_formatting("a", 1, 1:4, ">2")

Run the code above in your browser using DataLab