R 中基于规则的条件格式 (openxlsx)

标签 r conditional-formatting openxlsx

我正在尝试使用 R 中 openxlsx 包中的 conditionalFormatting() 函数。我希望该函数能够比较两列中的日期值 (AB),并且仅当值小于 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)

enter image description here

引用

https://ycphs.github.io/openxlsx/reference/conditionalFormatting.html

关于R 中基于规则的条件格式 (openxlsx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72851591/

相关文章:

r - 我可以避免向量中的操作的 for 循环吗?

r - 如何从 R 中的列表创建自动文本文件?

r - 从月份推断季度列,从季度推断月份列

excel - 设置固定范围的单元格的背景颜色

excel - 为什么这个 Excel 公式对于条件格式返回不同的结果?

r - 如何在 R 中使用 openxlsx 包编写 100 万行的 Excel 文件

r - 如何使用列中的多个字符对数据进行子集化

google-sheets - 如何根据 Google 表格中的 =Today() 突出显示包含行中工作日名称的单元格

r - 使用 openxlsx 将日期写入 excel 表作为具有自定义样式的日期格式

r - openxlsx 中的换行符