Create a new style to apply to worksheet cells
createStyle(
fontName = NULL,
fontSize = NULL,
fontColour = NULL,
numFmt = openxlsx_getOp("numFmt", "GENERAL"),
border = NULL,
borderColour = openxlsx_getOp("borderColour", "black"),
borderStyle = openxlsx_getOp("borderStyle", "thin"),
bgFill = NULL,
fgFill = NULL,
halign = NULL,
valign = NULL,
textDecoration = NULL,
wrapText = FALSE,
textRotation = NULL,
indent = NULL,
locked = NULL,
hidden = NULL
)
A name of a font. Note the font name is not validated. If fontName is NULL, the workbook base font is used. (Defaults to Calibri)
Font size. A numeric greater than 0. If fontSize is NULL, the workbook base font size is used. (Defaults to 11)
Colour of text in cell. A valid hex colour beginning with "#" or one of colours(). If fontColour is NULL, the workbook base font colours is used. (Defaults to black)
Cell formatting
GENERAL
NUMBER
CURRENCY
ACCOUNTING
DATE
LONGDATE
TIME
PERCENTAGE
FRACTION
SCIENTIFIC
TEXT
COMMA for comma separated thousands
For date/datetime styling a combination of d, m, y and punctuation marks
For numeric rounding use "0.00" with the preferred number of decimal places
Cell border. A vector of "top", "bottom", "left", "right" or a single string).
Top border
Bottom border
Left border
Right border
Top and bottom border
Left and right border
Top, Left and right border
All borders
Colour of cell border vector the same length as the number of sides specified in "border" A valid colour (belonging to colours()) or a valid hex colour beginning with "#"
Border line style vector the same length as the number of sides specified in "border"
No Border
thin border
medium border
dashed border
dotted border
thick border
double line border
Hairline border
medium weight dashed border
dash-dot border
medium weight dash-dot border
dash-dot-dot border
medium weight dash-dot-dot border
slanted dash-dot border
Cell background fill colour. A valid colour (belonging to colours()) or a valid hex colour beginning with "#". – Use for conditional formatting styles only.
Cell foreground fill colour. A valid colour (belonging to colours()) or a valid hex colour beginning with "#"
Horizontal alignment of cell contents
Left horizontal align cell contents
Right horizontal align cell contents
Center horizontal align cell contents
Justify horizontal align cell contents
A name Vertical alignment of cell contents
Top vertical align cell contents
Center vertical align cell contents
Bottom vertical align cell contents
Text styling.
Bold cell contents
Strikeout cell contents
Italicise cell contents
Underline cell contents
Double underline cell contents
Single accounting underline cell contents
Double accounting underline cell contents
Logical. If TRUE
cell contents will wrap to fit in column.
Rotation of text in degrees. 255 for vertical text.
Horizontal indentation of cell contents.
Whether cell contents are locked (if worksheet protection is turned on)
Whether the formula of the cell contents will be hidden (if worksheet protection is turned on)
A style object
## See package vignettes for further examples
## Modify default values of border colour and border line style
options("openxlsx.borderColour" = "#4F80BD")
options("openxlsx.borderStyle" = "thin")
## Size 18 Arial, Bold, left horz. aligned, fill colour #1A33CC, all borders,
style <- createStyle(
fontSize = 18, fontName = "Arial",
textDecoration = "bold", halign = "left", fgFill = "#1A33CC", border = "TopBottomLeftRight"
)
## Red, size 24, Bold, italic, underline, center aligned Font, bottom border
style <- createStyle(
fontSize = 24, fontColour = rgb(1, 0, 0),
textDecoration = c("bold", "italic", "underline"),
halign = "center", valign = "center", border = "Bottom"
)
# borderColour is recycled for each border or all colours can be supplied
# colour is recycled 3 times for "Top", "Bottom" & "Right" sides.
createStyle(border = "TopBottomRight", borderColour = "red")
#> A custom cell style.
#>
#> Cell formatting: GENERAL
#> Cell borders: Top: thin, Bottom: thin, Right: thin
#> Cell border colours: #FF0000, #FF0000, #FF0000
#>
#>
# supply all colours
createStyle(border = "TopBottomLeft", borderColour = c("red", "yellow", "green"))
#> A custom cell style.
#>
#> Cell formatting: GENERAL
#> Cell borders: Top: thin, Bottom: thin, Left: thin
#> Cell border colours: #FF0000, #FFFF00, #00FF00
#>
#>