wb <- createWorkbook()
## Add a worksheet and data
addWorksheet(wb, "Worksheet Name")
writeData(wb, 1, matrix(runif(100), ncol = 10), xy = c(1,1), colNames=FALSE)
writeData(wb, 1, matrix(sample(LETTERS, 100, rep = TRUE), ncol = 10), xy = c(1, 11), colNames=FALSE)
## Create a style
conditionalStyle <- createStyle(bgFill = "#FFFF00")
## Conditionally format cells:Rows 10 to 20 columns A to J (1:10)
conditionalFormat(wb, 1, cols = 1:10, rows = 1:10, rule = "< 0.5", style = conditionalStyle)
conditionalFormat(wb, 1, cols = 1:10, rows = 11:20, rule = '== "A"') # default style
## Save workbook
saveWorkbook(wb, "conditionalFormatExample.xlsx", overwrite = TRUE)
Run the code above in your browser using DataLab