Reputation: 21
I'm trying to use the conditionalFormatting()
function from the openxlsx
package in R. I would like the function to compare date values in two columns (A
and B
), and color the cell value in B
only if the value is smaller than A
. Is this a stretch?
conditionalFormatting(wb, "Sheet1", cols=12, rows=1:nrow(data), rule = 'B<A', style = myStyle)
Upvotes: 2
Views: 1366
Reputation: 35554
You could use rule = "$A2>$B2"
:
df <- data.frame(x = 1:6, y = 1:6 + c(-1, 1))
wb <- createWorkbook()
addWorksheet(wb, "sheet1")
writeData(wb, "sheet1", df)
conditionalFormatting(wb, "sheet1", cols = 2, rows = 2:(nrow(df)+1), rule = "$A2>$B2")
saveWorkbook(wb, "conditionalFormattingExample.xlsx", TRUE)
https://ycphs.github.io/openxlsx/reference/conditionalFormatting.html
Upvotes: 2