write.xlsx: write data to an xlsx file

Description Usage Arguments Details Value Author(s) See Also Examples

Description

write a data.frame or list of data.frames to an xlsx file

Usage

1
write.xlsx(x, file, asTable = FALSE, ...)

Arguments

x

object or a list of objects that can be handled by writeData to write to file

file

xlsx file name

asTable

write using writeDataTable as opposed to writeData

...

optional parameters to pass to functions:

  • createWorkbook

  • addWorksheet

  • writeData

  • freezePane

  • saveWorkbook

see details.

Details

Optional parameters are:

createWorkbook Parameters

addWorksheet Parameters

writeData/writeDataTable Parameters

freezePane Parameters

colWidths Parameters

saveWorkbook Parameters

columns of x with class Date or POSIXt are automatically styled as dates and datetimes respectively.

Value

A workbook object

Author(s)

Alexander Walker

See Also

addWorksheet

writeData

createStyle for style parameters

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## write to working directory
options("openxlsx.borderColour" = "#4F80BD") ## set default border colour
write.xlsx(iris, file = "writeXLSX1.xlsx", colNames = TRUE, borders = "columns")
write.xlsx(iris, file = "writeXLSX2.xlsx", colNames = TRUE, borders = "surrounding")


hs <- createStyle(textDecoration = "BOLD", fontColour = "#FFFFFF", fontSize=12,
                  fontName="Arial Narrow", fgFill = "#4F80BD")

write.xlsx(iris, file = "writeXLSX3.xlsx", colNames = TRUE, borders = "rows", headerStyle = hs)

## Lists elements are written to individual worksheets, using list names as sheet names if available
l <- list("IRIS" = iris, "MTCATS" = mtcars, matrix(runif(1000), ncol = 5))
write.xlsx(l, "writeList1.xlsx", colWidths = c(NA, "auto", "auto"))

## different sheets can be given different parameters
write.xlsx(l, "writeList2.xlsx", startCol = c(1,2,3), startRow = 2,
           asTable = c(TRUE, TRUE, FALSE), withFilter = c(TRUE, FALSE, FALSE))

awalker89/openxlsx documentation built on May 11, 2019, 4:09 p.m.