Learn R Programming

openxlsx2 (version 0.3.1)

style_mgr: style manager

Description

style manager

style manager

Arguments

Public fields

numfmt

numfmt-ids

font

font-ids

fill

fill-ids

border

border-ids

xf

xf-ids

dxf

dxf-ids

styles

styles as xml

Methods


Method new()

Creates a new wbStylesMgr object

Usage

style_mgr$new(
  numfmt = NA,
  font = NA,
  fill = NA,
  border = NA,
  xf = NA,
  dxf = NA,
  styles = NA
)

Arguments

numfmt

numfmt

font

font

fill

fill

border

border

xf

xf

dxf

dxf

styles

styles

Returns

a wbStylesMgr object


Method get_numfmt()

get numfmt ids

Usage

style_mgr$get_numfmt()


Method get_font()

get font ids

Usage

style_mgr$get_font()


Method get_fill()

get fill ids

Usage

style_mgr$get_fill()


Method get_border()

get border ids

Usage

style_mgr$get_border()


Method get_xf()

get xf ids

Usage

style_mgr$get_xf()


Method get_dxf()

get dxf ids

Usage

style_mgr$get_dxf()


Method get_numfmt_id()

get numfmt id by name

Usage

style_mgr$get_numfmt_id(name)

Arguments

name

name


Method get_font_id()

get font id by name

Usage

style_mgr$get_font_id(name)

Arguments

name

name


Method get_fill_id()

get fill id by name

Usage

style_mgr$get_fill_id(name)

Arguments

name

name


Method get_border_id()

get border id by name

Usage

style_mgr$get_border_id(name)

Arguments

name

name


Method get_xf_id()

get xf id by name

Usage

style_mgr$get_xf_id(name)

Arguments

name

name


Method get_dxf_id()

get dxf id by name

Usage

style_mgr$get_dxf_id(name)

Arguments

name

name


Method next_numfmt_id()

get next numfmt id

Usage

style_mgr$next_numfmt_id()


Method next_font_id()

get next font id

Usage

style_mgr$next_font_id()


Method next_fill_id()

get next fill id

Usage

style_mgr$next_fill_id()


Method next_border_id()

get next border id

Usage

style_mgr$next_border_id()


Method next_xf_id()

get next xf id

Usage

style_mgr$next_xf_id()


Method next_dxf_id()

get next xf id

Usage

style_mgr$next_dxf_id()


Method add()

add entry

Usage

style_mgr$add(style, style_name, skip_duplicates = TRUE)

Arguments

style

new_style

style_name

a unique name identifying the style

skip_duplicates

should duplicates be added?


Method clone()

The objects of this class are cloneable with this method.

Usage

style_mgr$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code
xlsxFile <- system.file("extdata", "oxlsx2_sheet.xlsx", package = "openxlsx2")
wb <- wb_load(xlsxFile)

# ## start style mgr
# style <- style_mgr$new(wb)
# style$initialize(wb)

# wb$styles_mgr$get_numfmt() |> print()
# wb$styles_mgr$next_numfmt_id() |> print()
# wb$styles_mgr$get_numfmt_id("numFmt-166")

# create new number format
new_numfmt <- create_numfmt(numFmtId = wb$styles_mgr$next_numfmt_id(), formatCode = "#,#")

# add it via stylemgr
wb$styles_mgr$add(new_numfmt, "test")

## get numfmts (invisible)
# z <- wb$styles_mgr$get_numfmt()
# z
wb$styles_mgr$styles$numFmts

## create and add huge font
new_huge_font <- create_font(sz = "20", name = "Arial", b = "1",
                             color = wb_colour(hex = "FFFFFFFF"))
wb$styles_mgr$add(new_huge_font, "arial_huge")

## create another font
new_font <- create_font(name = "Arial")
wb$styles_mgr$add(new_font, "arial")

## create and add new fill
new_fill <- create_fill(patternType = "solid", fgColor = wb_colour(hex = "FF00224B"))
wb$styles_mgr$add(new_fill, "blue")

# create new style with numfmt enabled
head_xf <- create_cell_style(
  horizontal = "center",
  textRotation = "45",
  numFmtId = "0",
  fontId = wb$styles_mgr$get_font_id("arial_huge"),
  fillId = wb$styles_mgr$get_fill_id("blue")
)

new_xf <- create_cell_style(
  numFmtId = wb$styles_mgr$get_numfmt_id("test"),
  fontId = wb$styles_mgr$get_font_id("arial")
)

## add new styles
wb$styles_mgr$add(head_xf, "head_xf")
wb$styles_mgr$add(new_xf, "new_xf")

## get cell style ids (invisible)
# z <- wb$styles_mgr$get_xf()

## get cell style id
# wb$styles_mgr$get_xf_id("new_xf")

 ## assign styles to cells
wb$set_cell_style("SUM", "B3:I3", wb$styles_mgr$get_xf_id("head_xf"))
wb$set_cell_style("SUM", "C7:C16", wb$styles_mgr$get_xf_id("new_xf"))
# wb_open(wb)

Run the code above in your browser using DataLab