The as_excel() function relies on the openxlsx2 package for creating an Excel Workbook object in R. These objects can be saved using save_excel() or export_xlsx().

as_excel(
  ...,
  sheet_names = NULL,
  autofilter = TRUE,
  autowidth = TRUE,
  rows_zebra = TRUE,
  cols_zebra = FALSE,
  freeze_top_row = TRUE,
  align = "center",
  table_style = "TableStyleMedium2",
  creator = Sys.info()["user"],
  department = read_secret("department.name"),
  project_number = project_get_current_id(ask = FALSE)
)

save_excel(xl, filename = NULL, overwrite = FALSE)

Arguments

...

data sets, use named items for multiple tabs (see Examples)

sheet_names

sheet names

autofilter

create autofilter on columns in first row

autowidth

automatically adjust columns widths

rows_zebra

create banded rows

cols_zebra

create banded columns

freeze_top_row

freeze the first row of the sheet

align

horizontal alignment of text

table_style

style(s) for each table, see below. This can also be a vector with the same length as ....

creator

name of the creator of the workbook

department

name of the department of the workbook

project_number

project number, to add project ID as the subject of the workbook

xl

Excel object, as created with as_excel() (or manually with the openxlsx2 package)

filename

file location to save Excel document to, defaults to a random filename in the current folder

overwrite

overwrite existing file

Supported Table Styles

For the argument table_style, use one or more of these table styles as character input. The default is TableStyleMedium2.

Examples

# creates a Workbook object
xl <- as_excel("this is a sheet" = mtcars,
               "another sheet" = anscombe)
#> Warning: Row names for object 1 (32x11, sheet 'this is a sheet') added as first column 'rownames'
#> Warning: In read_secret(): environmental variable 'secrets_file' not set
xl
#> A Workbook object.
#>  
#> Worksheets:
#>  Sheets: this is a sheet, another sheet 
#>  Write order: 1, 2

# then save it with save_excel() or export_xlsx()