createStyle {openxlsx} | R Documentation

## 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, 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

- 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

`border`

Cell border. A vector of "top", "bottom", "left", "right" or a single string).

- "top" Top border

- bottom Bottom border

- left Left border

- right Right border

- TopBottom or c("top", "bottom") Top and bottom border

- LeftRight or c("left", "right") Left and right border

- TopLeftRight or c("top", "left", "right") Top, Left and right border

- TopBottomLeftRight or c("top", "bottom", "left", "right") All borders

`borderColour` | 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 "#"

`borderStyle`

Border line style vector the same length as the number of sides specified in "border"

- 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 "#". – Use for conditional formatting styles only.
`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 vertical text.
`indent` | Horizontal indentation of cell contents.

### Value

A style object

### Author(s)

Alexander Walker

### See Also

`addStyle`

### Examples

    ## 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"))

[Package openxlsx version 4.1.0 Index]