Inserts a data.frame into a new formatted worksheet. The distinction between insert_worksheet and insert_worksheet_nh is that the former also generates a header with contact information using the function insert_header. Some arguments have default values which are pulled from the active user configuration. When using the default configuration, the logo and contact information of the Statistical Office of Kanton Zurich will be inserted.

insert_worksheet(
  wb,
  sheetname,
  data,
  title = NULL,
  source = NULL,
  metadata = NULL,
  grouplines = NULL,
  group_names = NULL,
  logo = getOption("statR_logo"),
  contactdetails = inputHelperContactInfo(),
  homepage = getOption("statR_homepage"),
  author = "user"
)

insert_worksheet_nh(
  wb,
  sheetname,
  data,
  title = NULL,
  source = NULL,
  metadata = NULL,
  grouplines = NULL,
  group_names = NULL
)

insert_header(
  wb,
  sheetname,
  logo = getOption("statR_logo"),
  contactdetails = inputHelperContactInfo(),
  homepage = getOption("statR_homepage"),
  auftrag_id = NULL,
  author = "user",
  openinghours = NULL,
  contact_col = 13
)

Arguments

wb

workbook object to add new worksheet to.

sheetname

Names of the worksheet in output file. Note that this name will be truncated to 31 characters, must be unique, and cannot contain some special characters (namely the following: /, \, ?, *, :, [, ]).

data

data to be included.

title

title to be put above the data.

source

source of the data. Default can be adjusted via user profiles

metadata

metadata information to be included. Defaults to NA, meaning no metadata are attached.

grouplines

Can be used to visually group variables. Values should either correspond to numeric column indices or column names, denoting the first variable in a group. Defaults to NA, meaning no lines are added.

group_names

A vector of names for groups to be displayed in a secondary header. Should be of the same length as grouplines, and cannot be used unless these are set. Defaults to NA, meaning no secondary header is created.

logo

File path to the logo to be included in the index-sheet. Defaults to the logo of the Statistical Office of Kanton Zurich. This can either be overridden with a path to an image file, or configured in a user profile.

contactdetails

Character vector with contact information to be displayed on the title sheet. By default uses inputHelperContactInfo() to construct it based on values defined in the active user configuration.

homepage

Homepage of data publisher. Default can be adjusted via user configuration.

author

defaults to the last two letters (initials) or numbers of the internal user name.

auftrag_id

An ID associated with the Excel file. Defaults to NULL ( no output).

openinghours

A character vector with office hours. Defaults to NULL ( no output).

contact_col

Column number at which the contact information should be inserted.

Note

This function does not output an .xlsx file on its own. A separate call to openxlsx::saveWorkbook() is required.

Examples

if (FALSE) {
# Initialize Workbook
wb <- openxlsx::createWorkbook()

# Insert mtcars dataset with STATZH design
insert_worksheet(
  wb, sheetname = "cars1", data = mtcars, title = "mtcars dataset",
  source = "Source: ...", metadata = "Note: ...",
  grouplines = c(5,8), group_names = c("First group", "Second group")
)

# The same, but without header
insert_worksheet_nh(
  wb, sheetname = "cars2", data = mtcars, title = "mtcars dataset (no header)",
  source = "Source: ...", metadata = "Note: ...",
  grouplines = c(5,8), group_names = c("First group", "Second group")
)
}