Learn R Programming

openxlsx2 (version 1.4)

wb_add_font: Modify font in a cell region

Description

Modify the font in a cell region with more precision You can specify the font in a cell with other cell styling functions, but wb_add_font() gives you more control.

Usage

wb_add_font(
  wb,
  sheet = current_sheet(),
  dims = "A1",
  name = "Aptos Narrow",
  color = wb_color(hex = "FF000000"),
  size = "11",
  bold = "",
  italic = "",
  outline = "",
  strike = "",
  underline = "",
  charset = "",
  condense = "",
  extend = "",
  family = "",
  scheme = "",
  shadow = "",
  vert_align = "",
  ...
)

Value

A wbWorkbook, invisibly

Arguments

wb

A Workbook object

sheet

the worksheet

dims

the cell range

name

Font name: default "Aptos Narrow"

color

An object created by wb_color()

size

Font size: default "11",

bold

bold, "single" or "double", default: ""

italic

italic

outline

outline

strike

strike

underline

underline

charset

charset

condense

condense

extend

extend

family

font family

scheme

font scheme

shadow

shadow

vert_align

vertical alignment

...

...

Details

wb_add_font() provides all the options openxml accepts for a font node, not all have to be set. Usually name, size and color should be what the user wants.

See Also

Other styles: wb_add_border(), wb_add_cell_style(), wb_add_fill(), wb_add_named_style(), wb_add_numfmt(), wb_cell_style

Examples

Run this code
 wb <- wb_workbook() %>% wb_add_worksheet("S1") %>% wb_add_data("S1", mtcars)
 wb %>% wb_add_font("S1", "A1:K1", name = "Arial", color = wb_color(theme = "4"))
# With chaining
 wb <- wb_workbook()$add_worksheet("S1")$add_data("S1", mtcars)
 wb$add_font("S1", "A1:K1", name = "Arial", color = wb_color(theme = "4"))

Run the code above in your browser using DataLab