Learn R Programming

XLConnect (version 1.1.0)

writeNamedRegionToFile: Writing named regions to an Excel file (wrapper function)

Description

Writes named regions to an Excel file.

Usage

writeNamedRegionToFile(file, data, name, formula=NA, ..., worksheetScope = NULL,
styleAction = XLC$STYLE_ACTION.XLCONNECT, clearNamedRegions=FALSE)

Arguments

file

The path name of the file to write to

data

Data to write

name

Name of the named region to write to

formula

If formula is specified, each item defines the formula of the named region identified by the corresponding entry of name. Use this if you want to create the document from scratch instead of writing to a template!

worksheetScope

Optional character vector with worksheet name(s) to limit the scope in which the name(s) to write to is/are expected to be found. If not specified, the first matching named region is written to. Use "" to specifically target a globally-scoped named region.

...

Additional arguments passed to writeNamedRegion

styleAction

Style action to be used when writing the data.
The default is XLC$STYLE_ACTION.XLCONNECT. See setStyleAction for more information.

clearNamedRegions

TRUE to clear content of existing named regions before writing data

Author

Thomas Themel
Mirai Solutions GmbH https://mirai-solutions.ch

See Also

writeNamedRegion, writeWorksheetToFile, readNamedRegionFromFile,
readWorksheetFromFile

Examples

Run this code
if (FALSE) {
# multiregion xlsx file from demoFiles subfolder of package XLConnect
demoExcelFile <- system.file("demoFiles/multiregion.xlsx", 
                             package = "XLConnect")

template <- "template-ws.xlsx"
file.copy(demoExcelFile, template) 

# Write single data.frame to a named region in an existing file
writeNamedRegionToFile(template, name = "Iris", iris)

# Write to a new file, defining the sheet and named region as we write.
# Format according to XLConnect defaults
writeNamedRegionToFile("iris.xlsx", name = "Iris", data = iris,
                       formula = "IrisData!$C$4", 
                       styleAction = "XLCONNECT")
# clean up
file.remove("iris.xlsx")
file.remove("template-ws.xlsx")
}

Run the code above in your browser using DataLab