openxlsx (version 2.0.1)

createStyle: Create a cell style

Description

Create a new style to apply to worksheet cells

Usage

createStyle(fontName = NULL, fontSize = NULL, fontColour = NULL,
  numFmt = "GENERAL", border = NULL,
  borderColour = getOption("openxlsx.borderColour", "black"),
  borderStyle = getOption("openxlsx.borderStyle", "thin"), bgFill = NULL,
  fgFill = NULL, halign = NULL, valign = NULL, textDecoration = NULL,
  wrapText = FALSE)

Arguments

fontName
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)
fontColour
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)
fontSize
Font size. A numeric greater than 0. If fontSize is NULL, the workbook base font size is used. (Defaults to 11)
numFmt
Cell formatting
  • GENERAL
NUMBER CURRENCY ACCOUNTING DATE LONGDATE TIME PERCENTAG

Value

  • A style object

item

  • border
  • Bottom
  • Left
  • Right
  • TopBottom
  • LeftRight
  • TopLeftRight
  • TopBottomLeftRight
  • borderColour
  • borderStyle
  • thin
  • medium
  • dashed
  • dotted
  • thick
  • double
  • hair
  • mediumDashed
  • dashDot
  • mediumDashDot
  • dashDotDot
  • mediumDashDotDot
  • slantDashDot
  • bgFill
  • fgFill
  • halign
  • right
  • center
  • valign
  • center
  • bottom
  • textDecoration
  • strikeout
  • italic
  • underline
  • underline2
  • wrapText

itemize

  • bold

See Also

addStyle

Examples

Run this code
## 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")

# supply all colours
createStyle(border = "TopBottomLeft", borderColour = c("red","yellow", "green"))

Run the code above in your browser using DataLab