Create a cell style

Description

Create a new style to apply to worksheet cells

Usage

1
2
3
4
5
6
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, textRotation = NULL, indent = NULL)

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)

fontSize

Font size. A numeric greater than 0. If fontSize is NULL, the workbook base font size is used. (Defaults to 11)

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)

numFmt

Cell formatting

  • GENERAL

  • NUMBER

  • CURRENCY

  • ACCOUNTING

  • DATE

  • LONGDATE

  • TIME

  • PERCENTAGE

  • FRACTION

  • SCIENTIFIC

  • COMMA for comma seperated thousands

  • For date/datetime styling a combination of d, m, y and punctuation marks

  • For numeric rouding use "0.00" with the preferred number of deciaml places

border

Cell border (Any combination of "Top", "Bottom", "Left", "Right" in any order).

  • Top Top border

  • Bottom Bottom border

  • Left Left border

  • Right Right border

  • TopBottom Top and bottom border

  • LeftRight Left and right border

  • TopLeftRight Top and Left border

  • TopBottomLeftRight All borders

borderColour

Colour of cell border. A valid colour (belonging to colours()) or a valid hex colour beginning with "#"

borderStyle

Border line style

  • none No Border

  • thin thin border

  • medium medium border

  • dashed dashed border

  • dotted dotted border

  • thick thick border

  • double double line border

  • hair Hairline border

  • mediumDashed medium weight dashed border

  • dashDot dash-dot border

  • mediumDashDot medium weight dash-dot border

  • dashDotDot dash-dot-dot border

  • mediumDashDotDot medium weight dash-dot-dot border

  • slantDashDot slanted dash-dot border

bgFill

Cell background fill colour. A valid colour (belonging to colours()) or a valid hex colour beginning with "#"

fgFill

Cell foreground fill colour. A valid colour (belonging to colours()) or a valid hex colour beginning with "#"

halign

Horizontal alignment of cell contents

  • left Left horizontal align cell contents

  • right Right horizontal align cell contents

  • center Center horizontal align cell contents

valign

A name Vertical alignment of cell contents

  • top Top vertical align cell contents

  • center Center vertical align cell contents

  • bottom Bottom vertical align cell contents

textDecoration

Text styling.

  • bold Bold cell contents

  • strikeout Strikeout cell contents

  • italic Italicise cell contents

  • underline Underline cell contents

  • underline2 Double underline cell contents

wrapText

Logical. If TRUE cell contents will wrap to fit in column.

textRotation

Rotation of text in degrees. 255 for vertial text.

indent

Horizontal indentation of cell contents.

Value

A style object

Author(s)

Alexander Walker

See Also

addStyle

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## 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"))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.