R6 class that manages fonts, fills, borders, and
cell formats in an xlsx workbook's styles.xml. Used internally
by sheet_write_data() and available for extensions.
xlsx_styles$new()Initialize styles from an xlsx package directory.
xlsx_styles$new(package_dir)package_dirpath to the unpacked xlsx directory
xlsx_styles$get_font_id()Get or create a font index.
xlsx_styles$get_font_id(
name = "Calibri",
size = 11,
bold = FALSE,
italic = FALSE,
underline = FALSE,
color = "000000"
)namefont family name
sizefont size in points
boldlogical, bold
italiclogical, italic
underlinelogical, underline
colorhex color string (6 chars, without #)
xlsx_styles$get_fill_id()Get or create a fill index.
xlsx_styles$get_fill_id(bg_color = "FFFFFF")bg_colorhex color string for fill background
xlsx_styles$get_border_id()Get or create a border index.
xlsx_styles$get_border_id(
top_style = NULL,
top_color = NULL,
bottom_style = NULL,
bottom_color = NULL,
left_style = NULL,
left_color = NULL,
right_style = NULL,
right_color = NULL
)top_styleborder style for top side
top_colorborder color for top side
bottom_styleborder style for bottom side
bottom_colorborder color for bottom side
left_styleborder style for left side
left_colorborder color for left side
right_styleborder style for right side
right_colorborder color for right side
xlsx_styles$get_style_id()Get or create a cell format (xf) index.
xlsx_styles$get_style_id(
font_id = 0L,
fill_id = 0L,
border_id = 0L,
num_fmt_id = 0L,
halign = NA,
valign = NA,
text_rotation = 0L,
wrap_text = FALSE
)font_idinteger, font index (0-based)
fill_idinteger, fill index (0-based)
border_idinteger, border index (0-based)
num_fmt_idinteger, number format id
halignhorizontal alignment
valignvertical alignment
text_rotationtext rotation angle (0-180)
wrap_textlogical, enable text wrapping
xlsx_styles$get_xf_id()Get or create a cell format index for a number format.
xlsx_styles$get_xf_id(num_fmt_id)num_fmt_idinteger, number format id
xlsx_styles$save()Save styles.xml to disk.
xlsx_styles$save()xlsx_styles$clone()The objects of this class are cloneable with this method.
xlsx_styles$clone(deep = FALSE)deepWhether to make a deep clone.