writeNamedRegion-methods | R Documentation |
Writes data to the named regions defined in a workbook
.
## S4 method for signature 'workbook,ANY'
writeNamedRegion(object, data, name, header,
overwriteFormulaCells, rownames, worksheetScope)
object |
The |
data |
Data to write |
name |
Name of the named region to write to |
header |
Specifies if the column names should be written. The default is |
overwriteFormulaCells |
Specifies if existing formula cells in the |
rownames |
Name ( |
worksheetScope |
Optional character vector with worksheet name(s) to limit the scope in
which the |
.
Writes data
to the named region specified by name
. Note
that data
is assumed to be a data.frame
and is coerced to
one if this is not already the case. The argument header
specifies if the column names should be written. Note also that the
arguments are vectorized and as such multiple named regions can be
written with one call. In this case data
is assumed to be a list
of data objects (data.frame
's).
Named regions are automatically redefined to the area occupied by the
written cells. This guarantees that the complete set of data can be
re-read using
readNamedRegion
. Also, this
allows the named region just to be defined as the top left cell to be
written to. There is no need to know the exact size of the data in advance.
When writing data to Excel, writeNamedRegion
further applies cell
styles to the cells as defined by the workbook
's
"style action" (see
setStyleAction
).
Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch
What are named regions/ranges?
https://web.archive.org/web/20240821110221/https://www.officearticles.com/excel/named_ranges_in_microsoft_excel.htm
How to create named regions/ranges?
https://www.youtube.com/watch?v=iAE9a0uRtpM
workbook
,
writeWorksheet
,
appendNamedRegion
,
appendWorksheet
,
readNamedRegion
,
readWorksheet
,
writeNamedRegionToFile
## Not run:
# Load workbook (create if not existing)
wb <- loadWorkbook("writeNamedRegion.xlsx", create = TRUE)
# Create a worksheet named 'mtcars'
createSheet(wb, name = "mtcars")
# Create a named region called 'mtcars' on the sheet called 'mtcars'
createName(wb, name = "mtcars", formula = "mtcars!$A$1")
# Write built-in data set 'mtcars' to the above defined named region
# (using header = TRUE)
writeNamedRegion(wb, mtcars, name = "mtcars")
createSheet(wb, name="iris")
setActiveSheet(wb, "iris")
# Do the same with the iris data set, with a worksheet-scoped name
createName(wb, name = "iris", formula = "iris!$A$1", worksheetScope = "iris")
writeNamedRegion(wb, iris, name = "iris", worksheetScope="iris")
# Save workbook (this actually writes the file to disk)
saveWorkbook(wb)
# clean up
file.remove("writeNamedRegion.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.