as_wb()
converts a data frame, a list of data frames, or an Excel file path
to a wbWorkbook object.
Usage
as_wb(
x,
...,
sheet_names = NULL,
creator = NULL,
title = NULL,
subject = NULL,
category = NULL,
datetime_created = Sys.time(),
theme = NULL,
keywords = NULL,
properties = NULL,
call = caller_env()
)
Arguments
- x
A data frame, a list of data frames, a file path for an Excel file, or a
wbWorkbook
object. AwbWorkbook
is returned "as is" ignoring all other parameters. A file path is loaded to a data frame usingopenxlsx2::wb_to_df()
.- ...
Arguments passed on to
wb_add_data_ext
as_table
Default
FALSE
. IfTRUE
, useopenxlsx2::wb_add_data_table()
to add data to workbook. IfFALSE
, useopenxlsx2::wb_add_data()
. Additional parameters in...
are passed to one function or the other depending on this value.labels
Method for handling column labels. "drop" (default) or "row_before". If "row_before", insert column labels in the row before the column names.
list_columns
String, one of "collapse" (default), "drop", or "asis"
sep
String to use in collapsing list columns. Ignored unless
list_columns = "collapse"
. Defaults to"; "
.geometry
String, one of "drop" (default), "coords", or "wkt". "coords" uses
sf::st_centroid()
to convert input to POINT geometry, transforms geometry to EPSG:4326, converts geometry to coordinates, and adds new columns with names matchingcoords
. "wkt" converts geometry to a Well Known Text (WKT) character vector usingsf::st_as_text()
and replaces the existing geometry column (keeping the existing sf column name).coords
Length 2 character vector with column names to add if
geometry = "coords"
. Must be length 2 in longitude, latitude order.wb
A Workbook object containing a worksheet.
sheet
The worksheet to write to. Can be the worksheet index or name.
start_row
A vector specifying the starting row to write
x
to.
- sheet_names
Optional character vector of worksheet names.
- creator
Creator of the workbook (your name). Defaults to login username or
options("openxlsx2.creator")
if set.- title, subject, category, keywords
Additional arguments passed to
openxlsx2::wb_workbook()
.- datetime_created
The time of the workbook is created
- theme
Optional theme identified by string or number. See Details for options.
- properties
A named list (typically from
openxlsx2::wb_get_properties()
) used to set new workbook properties for any values set toNULL
.datetime_created
defaults toSys.time()
so must be set toNULL
to inherit value fromproperties
.- call
The execution environment of a currently running function, e.g.
caller_env()
. The function will be mentioned in error messages as the source of the error. See thecall
argument ofabort()
for more information.
Examples
as_wb(mtcars[1:3, ])
#> A Workbook object.
#>
#> Worksheets:
#> Sheets: Sheet 1
#> Write order: 1
as_wb(list(mtcars[1:3, ], mtcars[4:6, ]))
#> A Workbook object.
#>
#> Worksheets:
#> Sheets: Sheet 1, Sheet 2
#> Write order: 1, 2