
Setting the data format for the DATA_FORMAT_ONLY style action
setDataFormatForType-methods.RdSets the data format for a specific data type as used by the DATA_FORMAT_ONLY style action.
Arguments
- object
The
workbookto use- type
The data type for which to set the
format.- format
A data format string
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.
Author
Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch
Examples
if (FALSE) { # \dontrun{
# 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")
} # }