我正在尝试使用 R 中 openxlsx
包中的 conditionalFormatting()
函数。我希望该函数能够比较两列中的日期值 (A
和 B
),并且仅当值小于 A
时,才为 B
中的单元格值着色。这是一个延伸吗?
conditionalFormatting(wb, "Sheet1", cols=12, rows=1:nrow(data), rule = 'B<A', style = myStyle)
最佳答案
您可以使用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
关于R 中基于规则的条件格式 (openxlsx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72851591/