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_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)
Run the code above in your browser using DataLab