This function is a wrapper for openxlsx2::wb_add_worksheet() and openxlsx2::wb_add_data(), but also does some extra formatting via more {openxlsx2} functions. Note that {openxlsx2} workbooks are modified in place, so wb is updated whether or not the result is assigned.

add_sheet(
  wb,
  data,
  sheet_name = NULL,
  col_width = "auto",
  col_width_min = 5,
  col_width_max = 25,
  grid_lines = FALSE,
  freeze_first_row = TRUE,
  freeze_first_col = FALSE,
  add_filters = TRUE,
  row_height = 15,
  text_wrap = TRUE,
  date_format = "yyyy-mm-dd",
  datetime_format = "yyyy-mm-dd hh:mm:ss",
  na = NULL,
  sheetName = deprecated(),
  colWidth = deprecated(),
  colWidthMin = deprecated(),
  colWidthMax = deprecated(),
  gridLines = deprecated(),
  freezefirstRow = deprecated(),
  freezefirstCol = deprecated(),
  addFilters = deprecated(),
  rowheight = deprecated(),
  textwrap = deprecated(),
  dateformat = deprecated(),
  datetimeformat = deprecated()
)

Arguments

wb

A Workbook object to attach the new worksheet

data

Object to be written. For classes supported look at the examples in {openxlsx2}.

sheet_name

The name of the worksheet that is to be created and have data written into. Defaults to the data object name if left empty. Must not be the name of an existing sheet (case-insensitive); illegal characters are removed and names are shortened to 31 characters by {openxlsx2} (with a warning).

col_width

For all columns: column width. Can either be a spreadsheet column width or "auto" for automatic sizing

col_width_min

For all columns: minimum column width

col_width_max

For all columns: maximum column width

grid_lines

If FALSE, the worksheet grid lines will be hidden

freeze_first_row

If TRUE, freezes the first row

freeze_first_col

If TRUE, freezes the first column

add_filters

If TRUE, adds filters to worksheet columns

row_height

Row height in spreadsheet row height units

text_wrap

If TRUE, all cells are formatted via text wrap so their content never spills into adjacent empty cells

date_format

If not "none" (default is "yyyy-mm-dd"), all date-formatted columns in data are explicitly formatted with numfmt = "yyyy-mm-dd"

datetime_format

If not "none" (default is "yyyy-mm-dd hh:mm:ss"), all datetime-formatted columns in data are explicitly formatted with numfmt = "yyyy-mm-dd hh:mm:ss"

na

Value used for replacing NA values from data. The default NULL leaves those cells empty.

sheetName

[Deprecated] Use sheet_name.

colWidth

[Deprecated] Use col_width.

colWidthMin

[Deprecated] Use col_width_min.

colWidthMax

[Deprecated] Use col_width_max.

gridLines

[Deprecated] Use grid_lines.

freezefirstRow

[Deprecated] Use freeze_first_row.

freezefirstCol

[Deprecated] Use freeze_first_col.

addFilters

[Deprecated] Use add_filters.

rowheight

[Deprecated] Use row_height.

textwrap

[Deprecated] Use text_wrap.

dateformat

[Deprecated] Use date_format.

datetimeformat

[Deprecated] Use datetime_format.

Value

The Workbook object, invisibly

Examples

library(BioMathR)
wb1 <- create_wb()
add_sheet(wb = wb1, data = mtcars)

wb2 <- create_wb()
add_sheet(wb2, mtcars, "The cars sheet")