Writes a data frame to an xlsx file. To create an xlsx with (multiple) named
sheets, simply set x
to a named list of data frames.
Usage
write_xlsx(
x,
path = tempfile(fileext = ".xlsx"),
col_names = TRUE,
format_headers = TRUE,
use_zip64 = FALSE
)
Arguments
- x
data frame or named list of data frames that will be sheets in the xlsx
- path
a file name to write to
- col_names
write column names at the top of the file?
- format_headers
make the
col_names
in the xlsx centered and bold- use_zip64
use zip64 to enable support for 4GB+ xlsx files. Not all platforms can read this.
Details
Currently supports strings, numbers, booleans and dates. Formatting options may be added in future versions.
Examples
# Roundtrip example with single excel sheet named 'mysheet'
tmp <- write_xlsx(list(mysheet = iris))
readxl::read_xlsx(tmp)
#> # A tibble: 150 × 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
#> 7 4.6 3.4 1.4 0.3 setosa
#> 8 5 3.4 1.5 0.2 setosa
#> 9 4.4 2.9 1.4 0.2 setosa
#> 10 4.9 3.1 1.5 0.1 setosa
#> # ℹ 140 more rows