% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/write_xlsx.R
\name{write_xlsx}
\alias{write_xlsx}
\alias{writexl}
\title{Export to xlsx}
\usage{
write_xlsx(
  x,
  path = tempfile(fileext = ".xlsx"),
  col_names = TRUE,
  format_headers = TRUE,
  na = NA,
  use_zip64 = FALSE,
  constant_memory = NA,
  constant_memory_threshold = 128 * 1024^2
)
}
\arguments{
\item{x}{a data frame, an [xl_sheet], an [xl_workbook], or a (named) list of
data frames / `xl_sheet`s that become the sheets in the xlsx}

\item{path}{a file name to write to}

\item{col_names}{write column names as the header row at the top of the sheet?}

\item{format_headers}{apply the workbook's header format to that header row?
The default header format is bold and centered; change it with
\code{\link{xl_properties}(header_format = )}.}

\item{na}{what to write where a value has none. `NA` (the default) leaves
the cell blank, as writexl has always done; anything else is written in
its place, keeping its own type. Shorthand for
\code{\link{xl_properties}(na = )}, so give it there instead when `x` is
already an [xl_workbook]. A column or a single cell can override it: see
[xl_col_spec()] and [xl_cell_general()].}

\item{use_zip64}{use \href{https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64}{zip64}
to enable support for 4GB+ xlsx files. Not all platforms can read this.}

\item{constant_memory}{stream rows to disk instead of building the whole
workbook in memory. `NA` (the default) decides per workbook: on for large
data, off for small, and always off when a feature needs it off. `TRUE`
forces it on for a workbook that would otherwise be judged too small;
`FALSE` forces it off. Features that cannot be written while streaming ---
merged ranges, tables, embedded images and multi-cell array formulas ---
turn it off regardless, with a warning if `TRUE` was asked for, because
the alternative is a file that opens cleanly and is missing cells.}

\item{constant_memory_threshold}{how much extra memory not streaming would
have to cost, in bytes, before streaming is worth it. Default 128 MiB.
The cost is *estimated* from the number of cells in the workbook, using a
fixed per-cell figure calibrated against a range of data; the true cost
varies with the data, and is lowest for text that repeats. Streaming saves
memory but produces slightly larger files, so it is not used for workbooks
small enough that the saving would not be noticed.}
}
\description{
Writes a data frame to an xlsx file. To create an xlsx with (multiple) named
sheets, simply set \code{x} to a named list of data frames.
}
\details{
Supports strings, numbers, booleans and dates automatically. For cell
formatting (fonts, fills, borders, number formats, ...), worksheet layout
(column widths, frozen panes, ...), and workbook metadata, wrap columns with
\code{\link{xl_cell_general}}, sheets with \code{\link{xl_sheet}}, and the
whole workbook with \code{\link{xl_workbook}}. See the "Formatting and
workbook properties" vignette and \code{\link{xl_format}}.

\if{html}{
\out{
<link rel="stylesheet" type="text/css" href="https://jeroen.github.io/clippy/clippy.min.css" media="all">
<script src="https://jeroen.github.io/clippy/bundle.js"></script>
}}
}
\examples{
# Roundtrip example with single excel sheet named 'mysheet'
tmp <- write_xlsx(list(mysheet = iris))
readxl::read_xlsx(tmp)
}
\seealso{
Other workbook settings:
\code{\link[=xl_properties]{xl_properties()}},
\code{\link[=xl_workbook]{xl_workbook()}}
}
\concept{workbook settings}
