Build a workbook from a data.frame or named list
buildWorkbook(x, asTable = FALSE, ...)
A data.frame or a (named) list of objects that can be handled by
writeData()
or writeDataTable()
to write to file
If TRUE
will use writeDataTable()
rather
than writeData()
to write x
to the file (default:
FALSE
)
Additional arguments passed to writeData()
,
writeDataTable()
, setColWidths()
(see Optional
Parameters)
A Workbook object
This function can be used as shortcut to create a workbook object from a
data.frame or named list. If names are available in the list they will be
used as the worksheet names. The parameters in ...
are collected
and passed to writeData()
or writeDataTable()
to
initially create the Workbook objects then appropriate parameters are
passed to setColWidths()
.
columns of x with class Date or POSIXt are automatically styled as dates and datetimes respectively.
createWorkbook Parameters
A string specifying the workbook author
addWorksheet Parameters
Name of the worksheet
A logical. If FALSE
, the worksheet grid lines will be hidden.
Colour of the worksheet tab. A valid colour (belonging to colours()) or a valid hex colour beginning with "#".
A numeric between 10 and 400. Worksheet zoom level as a percentage.
writeData/writeDataTable Parameters
A vector specifying the starting column(s) to write df
A vector specifying the starting row(s) to write df
An alternative to specifying startCol and startRow individually. A vector of the form c(startCol, startRow)
If TRUE
, column names of x are written.
If TRUE
, row names of x are written.
Custom style to apply to column names.
Either "surrounding", "columns" or "rows" or NULL. If "surrounding", a border is drawn around the
data. If "rows", a surrounding border is drawn a border around each row. If "columns", a surrounding border is drawn with a border
between each column. If "all
" all cell borders are drawn.
Colour of cell border
Border line style.
If TRUE
, NA values are converted to #N/A (or na.string
, if not NULL) in Excel, else NA cells will be empty. Defaults to FALSE.
If not NULL, and if keepNA
is TRUE
, NA values are converted to this string in Excel. Defaults to NULL.
freezePane Parameters
Top row of active region to freeze pane.
Furthest left column of active region to freeze pane.
If TRUE
, freezes the first row (equivalent to firstActiveRow = 2)
If TRUE
, freezes the first column (equivalent to firstActiveCol = 2)
colWidths Parameters
May be a single value for all columns (or "auto"), or a list of vectors that will be recycled for each sheet (see examples)
x <- data.frame(a = 1, b = 2)
wb <- buildWorkbook(x)
y <- list(a = x, b = x, c = x)
buildWorkbook(y, asTable = TRUE)
#> A Workbook object.
#>
#> Worksheets:
#> Sheet 1: "a"
#>
#>
#> Sheet 2: "b"
#>
#>
#> Sheet 3: "c"
#>
#>
#>
#> Worksheet write order: 1, 2, 3
#> Active Sheet 1: "a"
#> Position: 1
#>
buildWorkbook(y, asTable = TRUE, tableStyle = "TableStyleLight8")
#> A Workbook object.
#>
#> Worksheets:
#> Sheet 1: "a"
#>
#>
#> Sheet 2: "b"
#>
#>
#> Sheet 3: "c"
#>
#>
#>
#> Worksheet write order: 1, 2, 3
#> Active Sheet 1: "a"
#> Position: 1
#>