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