Skip to contents

[Experimental]

Usage

set_excel_fmt_class(
  data,
  cols,
  fmt_class = "currency",
  multiple = TRUE,
  strict = FALSE
)

Arguments

data

A data frame with columns to format.

cols

Column names or numbers to modify.

fmt_class

Excel style class, one of: c("currency", "accounting", "hyperlink", "percentage", "scientific", "formula"). Length is recycled to match length of cols using vctrs::vec_recycle().

multiple

Whether arg may contain zero or several values.

strict

If TRUE, error if any character values in cols are not included in the names of data. Default FALSE.

Value

A data frame matching data with fmt_class added to the class of the specified cols.

Details

set_excel_fmt_class() applies a style to each specified column. See the openxlsx2 documentation for more information on this feature: https://janmarvin.github.io/openxlsx2/articles/openxlsx2_style_manual.html#numfmts2

Examples

data <- data.frame(price = c(1, 2), pct = c(0.1, 0.2))

set_excel_fmt_class(data, cols = c("price", "pct"), fmt_class = c("currency", "percentage"))
#>   price pct
#> 1     1 0.1
#> 2     2 0.2