Skip to contents

style manager

style manager

Public fields

numfmt

numfmt-ids

font

font-ids

fill

fill-ids

border

border-ids

xf

xf-ids

cellStyle

cellStyle-ids

cellStyleXf

cellStyleXf-ids

dxf

dxf-ids

tableStyle

tableStyle-ids

defaultTableStyle

defaultTableStyle

defaultPivotStyle

defaultPivotStyle

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,
  cellStyle = NA,
  cellStyleXf = NA,
  dxf = NA,
  styles = NA
)

Arguments

numfmt

numfmt

font

font

fill

fill

border

border

xf

xf

cellStyle

cellStyles

cellStyleXf

cellStylesXf

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_cellStyle()

get cellstyle ids

Usage

style_mgr$get_cellStyle()


Method get_cellStyleXf()

get cellstylexf ids

Usage

style_mgr$get_cellStyleXf()


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_cellStyle_id()

get cellstyle id by name

Usage

style_mgr$get_cellStyle_id(name)

Arguments

name

name


Method get_cellStyleXf_id()

get cellstyleXf id by name

Usage

style_mgr$get_cellStyleXf_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 get_tableStyle_id()

get tableStyle id by name

Usage

style_mgr$get_tableStyle_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_cellstyle_id()

get next xf id

Usage

style_mgr$next_cellstyle_id()


Method next_cellstylexf_id()

get next xf id

Usage

style_mgr$next_cellstylexf_id()


Method next_dxf_id()

get next dxf id

Usage

style_mgr$next_dxf_id()


Method next_tableStyle_id()

get next tableStyle id

Usage

style_mgr$next_tableStyle_id()


Method getstyle_ids()

get named style ids

Usage

style_mgr$getstyle_ids(name)

Arguments

name

name


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 init_named_style()

Usage

style_mgr$init_named_style(name, font_name = "Arial", font_size = 11)

Arguments

name

style name

font_name, font_size

optional else the default of the theme

wb

wbWorkbook

Details

possible styles are: "20% - Accent1" "20% - Accent2" "20% - Accent3" "20% - Accent4" "20% - Accent5" "20% - Accent6" "40% - Accent1" "40% - Accent2" "40% - Accent3" "40% - Accent4" "40% - Accent5" "40% - Accent6" "60% - Accent1" "60% - Accent2" "60% - Accent3" "60% - Accent4" "60% - Accent5" "60% - Accent6" "Accent1" "Accent2" "Accent3" "Accent4" "Accent5" "Accent6" "Bad" "Calculation" "Check Cell" "Comma" "Comma [0]" "Currency" "Currency [0]" "Explanatory Text" "Good" "Heading 1" "Heading 2" "Heading 3" "Heading 4" "Input" "Linked Cell" ”Neutral" "Normal" "Note" "Output" "Per cent" "Title" "Total" "Warning Text"


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

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
#> [1] "<numFmt numFmtId=\"164\" formatCode=\"mmm\\-yy\"/>"
#> [2] "<numFmt numFmtId=\"165\" formatCode=\"#,##0,\"/>"  
#> [3] "<numFmt numFmtId=\"166\" formatCode=\"#0\"/>"      
#> [4] "<numFmt numFmtId=\"167\" formatCode=\"0.00\\ %\"/>"
#> [5] "<numFmt numFmtId=\"168\" formatCode=\"0\\ %\"/>"   
#> [6] "<numFmt numFmtId=\"169\" formatCode=\"#,#\"/>"     

## create and add huge font
new_huge_font <- create_font(sz = "20", name = "Arial", b = "1",
                             color = wb_color(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_color(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)