我正在尝试根据该行中的一列中的openxlsx
文本填充 Excel 工作簿中的一行。例如,如果单元格C3
包含,A
则突出显示第 3 行。
理想情况下,这不会conditionalFormatting
。我希望它是基于单元格中文本的行的实际颜色,但conditionalFormatting
似乎是唯一的选择。如果我能把它变成实际的颜色,请告诉我。
下面的代码显示您可以根据该行中value
的单元格突出显示该行,但如果您尝试使用文本则不能。此外,如果type
设置为contains
那么它似乎不接受任何样式。
wb <- createWorkbook()
addWorksheet(wb, "Dependent on")
addWorksheet(wb, "containsText")
negStyle <- createStyle(fontColour = "#9C0006", bgFill = "#FFC7CE")
posStyle <- createStyle(fontColour = "#006100", bgFill = "#C6EFCE")
## highlight row based on value in column 2
writeData(wb, "Dependent on", data.frame(x = 1:10, y = runif(10)), startRow = 15)
conditionalFormatting(wb, "Dependent on", cols=1:2, rows=16:25, rule="$B16<0.5", style = negStyle)
conditionalFormatting(wb, "Dependent on", cols=1:2, rows=16:25, rule="$B16>=0.5", style = posStyle)
## cells containing text
fn <- function(x) paste(sample(LETTERS, 10), collapse = "-")
writeData(wb, "containsText", data.frame(letters = sapply(1:10, fn), numbers = 1:10))
conditionalFormatting(wb, "containsText", cols = 1:2, rows = 1:10, type = "contains", rule = "A")
openXL(wb) ## opens a temp version