write_xlsx | R Documentation |
Write a data frame or list of data frames to an xlsx file.
write_xlsx(x, file, as_table = FALSE, ...)
x |
An object or a list of objects that can be handled by |
file |
An optional xlsx file name. If no file is passed, the object is not written to disk and only a workbook object is returned. |
as_table |
If |
... |
Arguments passed on to
|
columns of x
with class Date
or POSIXt
are automatically
styled as dates and datetimes respectively.
A workbook object
## write to working directory
write_xlsx(iris, file = temp_xlsx(), col_names = TRUE)
write_xlsx(iris,
file = temp_xlsx(),
col_names = TRUE
)
## Lists elements are written to individual worksheets, using list names as sheet names if available
l <- list("IRIS" = iris, "MTCARS" = mtcars, matrix(runif(1000), ncol = 5))
write_xlsx(l, temp_xlsx(), col_widths = c(NA, "auto", "auto"))
## different sheets can be given different parameters
write_xlsx(l, temp_xlsx(),
start_col = c(1, 2, 3), start_row = 2,
as_table = c(TRUE, TRUE, FALSE), with_filter = c(TRUE, FALSE, FALSE)
)
# specify column widths for multiple sheets
write_xlsx(l, temp_xlsx(), col_widths = 20)
write_xlsx(l, temp_xlsx(), col_widths = list(100, 200, 300))
write_xlsx(l, temp_xlsx(), col_widths = list(rep(10, 5), rep(8, 11), rep(5, 5)))
# set base font color to automatic so LibreOffice dark mode works as expected
write_xlsx(l, temp_xlsx(), font_color = wb_color(auto = TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.