Learn R Programming

openxlsx (version 1.0.3)

writeDataTable: Write to a worksheet and format as a table

Description

Write to a worksheet and format as a table

Usage

writeDataTable(wb, sheet, x, startCol = 1, startRow = 1, xy = NULL,
  colNames = TRUE, rowNames = FALSE, tableStyle = "TableStyleMedium2")

Arguments

wb
A Workbook object containing a worksheet.
sheet
The worksheet to write to. Can be the worksheet index or name.
x
A dataframe.
startCol
A vector specifiying the starting columns(s) to write df
startRow
A vector specifiying 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
If TRUE, column names of x are written.
rowNames
If TRUE, data.frame row names of x are written.
tableStyle
Any excel table style name.

Details

columns of x with class Date, POSIXct of POSIXt are automatically styled as dates.

See Also

addWorksheet writeData

Examples

Run this code
## see package vignette for further examples.

wb <- createWorkbook("Edgar Anderson")

addWorksheet(wb, "S1")
addWorksheet(wb, "S2")
addWorksheet(wb, "S3")

## write data formatted as excel table with table filters
# default table style is "TableStyleMedium2"
writeDataTable(wb, "S1", x = iris)

writeDataTable(wb, "S2", x = mtcars, xy = c("B", 3), rowNames=TRUE, tableStyle="TableStyleLight9")

writeDataTable(wb, "S3", x = mtcars, startRow = 4, rowNames=TRUE, tableStyle="TableStyleMedium17")

saveWorkbook(wb, "writeDataTableExample.xlsx", overwrite = TRUE)

Run the code above in your browser using DataLab