Build a workbook from a data.frame or named list

buildWorkbook(x, asTable = FALSE, ...)

Arguments

x

A data.frame or a (named) list of objects that can be handled by writeData() or writeDataTable() to write to file

asTable

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)

Value

A Workbook object

Details

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.

Optional Parameters

createWorkbook Parameters

creator

A string specifying the workbook author

addWorksheet Parameters

sheetName

Name of the worksheet

gridLines

A logical. If FALSE, the worksheet grid lines will be hidden.

tabColour

Colour of the worksheet tab. A valid colour (belonging to colours()) or a valid hex colour beginning with "#".

zoom

A numeric between 10 and 400. Worksheet zoom level as a percentage.

writeData/writeDataTable Parameters

startCol

A vector specifying the starting column(s) to write df

startRow

A vector specifying the starting row(s) to write df

xy

An alternative to specifying startCol and startRow individually. A vector of the form c(startCol, startRow)

colNames or col.names

If TRUE, column names of x are written.

rowNames or row.names

If TRUE, row names of x are written.

headerStyle

Custom style to apply to column names.

borders

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.

borderColour

Colour of cell border

borderStyle

Border line style.

keepNA

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.

na.string

If not NULL, and if keepNA is TRUE, NA values are converted to this string in Excel. Defaults to NULL.

freezePane Parameters

firstActiveRow

Top row of active region to freeze pane.

firstActiveCol

Furthest left column of active region to freeze pane.

firstRow

If TRUE, freezes the first row (equivalent to firstActiveRow = 2)

firstCol

If TRUE, freezes the first column (equivalent to firstActiveCol = 2)

colWidths Parameters

colWidths

May be a single value for all columns (or "auto"), or a list of vectors that will be recycled for each sheet (see examples)

See also

Author

Jordan Mark Barbone

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
#>