Color cell in excel based on number of characters.

How to use openxlsx::conditionalFormatting to check number of charachters in cell and then color if length of string less than 10.

not able to write the "rule"

I do not have Excel with which to test this but it works when I open the xlsx file in OpenOffice. Cells B1 and B3 have a light red background. The code is largely from the openxlsx package documentation.

library(openxlsx)

wb <- createWorkbook()
addWorksheet(wb, "MySheet")
negStyle <- createStyle(fontColour = "#9C0006", bgFill = "#FFC7CE")
writeData(wb, "MySheet", c("ABCDE", "ABCDEFGHIJK", "AB"), startCol=2)
conditionalFormatting(wb, "MySheet", cols=2, rows=1:3, rule="LEN(B1)<10", style = negStyle)
saveWorkbook(wb, "ExcelOut.xlsx", overwrite = TRUE)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.