Setting the cell style per data type for the DATATYPE style action

Share:

Description

Sets the cell style for a specific data type as used by the DATATYPE style action.

Usage

1
2
## S4 method for signature 'workbook'
setCellStyleForType(object,type,style)

Arguments

object

The workbook to use

type

The data type for which to set the style

style

The cellstyle to set

Details

Based on the (cell) data type the DATATYPE style action (see setStyleAction) sets the cellstyle for the corresponding cells. The data type is normally specified via a corresponding data type constant from the XLC object.

Author(s)

Martin Studer
Mirai Solutions GmbH http://www.mirai-solutions.com

See Also

workbook, getCellStyleForType, setStyleAction

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
file.copy(system.file("demoFiles/template2.xlsx", 
                      package = "XLConnect"),
          "datatype.xlsx", overwrite = TRUE)

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

# Create a new cell style to be used
cs <- createCellStyle(wb, name = "mystyle")

# Set data format (number format) as numbers with aligned fractions
setDataFormat(cs, format = "# ???/???")

# Define the above created cell style as style to be used for
# numerics
setCellStyleForType(wb, type = XLC$"DATA_TYPE.NUMERIC", style = cs)
# Could also say cs <- setCellStyleForType(wb, "numeric")
          
# Set style action to 'datatype'
setStyleAction(wb, XLC$"STYLE_ACTION.DATATYPE")

# 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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.