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

setDataFormatForType-methodsR Documentation

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 signature '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

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(s)

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

See Also

workbook, setStyleAction

Examples

## Not run: 
# 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")

## End(Not run)

miraisolutions/xlconnect documentation built on April 19, 2024, 2:40 p.m.