Learn R Programming

XLConnect (version 1.0.7)

setDataFormatForType-methods: Setting the data format for the DATA_FORMAT_ONLY style action

Description

Sets the data format for a specific data type as used by the DATA_FORMAT_ONLY style action.

Usage

# S4 method for workbook
setDataFormatForType(object,type,format)

Arguments

object

The workbook to use

type

The data type for which to set the format.

format

A data format string

Author

Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch

Details

Based on the (cell) data type the DATA_FORMAT_ONLY style action (see setStyleAction) sets the data format for the corresponding cells. The data type is normally specified via a corresponding data type constant from the XLC object. Data formats are specified the standard Excel way. Refer to the Excel help or to the link below for more information.

See Also

workbook, setStyleAction

Examples

Run this code
if (FALSE) {
# Copy existing Excel template to working directory
file.copy(system.file("demoFiles/template2.xlsx", 
                      package = "XLConnect"),
          "dataformat.xlsx", overwrite = TRUE)

# Load workbook
wb <- loadWorkbook("dataformat.xlsx")

# Set the data format for numeric columns (cells)
# (keeping the defaults for all other data types)
setDataFormatForType(wb, type = XLC$"DATA_TYPE.NUMERIC", 
                     format = "0.00")

# Set style action to 'data format only'
setStyleAction(wb, XLC$"STYLE_ACTION.DATA_FORMAT_ONLY")

# Write built-in data set 'mtcars' to the named region 
# 'mtcars' as defined by the Excel template.
writeNamedRegion(wb, mtcars, name = "mtcars")

# Save workbook
saveWorkbook(wb)

# clean up
file.remove("dataformat.xlsx")
}

Run the code above in your browser using DataLab