title: Conditionally Highlight Cells in Excel based on text value from another column using openxlsx R
body: <p>I have an excel workbook with columns that contain flags (update vs. no) that looks at two adjacent columns and checks if the two cells contain the same data points. If not it is flagged as "update" in the 1st cell and I would like to highlight the next two cells adjacent to the "update" cell.</p>
  
  <p><strong>Working Example</strong> </p>
  
  <pre><code>library(openxlsx)
  
  animals &lt;- c("Cat","Mice","Dog","Bird","Cat","Cat")
  colors &lt;- c("Grey","White","Black","Blue","Black","Orange")
  store &lt;- c("Pet Shop","Online","Pets Mart","Walmart","Online","Pets Mart")
  
  df &lt;- cbind(animals,colors,store)
  
  setwd('C:/Users/WORKING DIRECTORY')
  
  write.xlsx(df, file ="test_test.xlsx",row.names = FALSE, sheetName= "Data")
  </code></pre>
  
  <p><strong>openxlsx code to highlight text values</strong></p>
  
  <pre><code>df &lt;- loadWorkbook(file = "test_test.xlsx")
  
  highlighting &lt;- createStyle(bgFill = "#fff400")
  
  conditionalFormatting(df, "Data", cols = 1:3, rows = 2:7, type = "contains", rule = "A2=Cat", style = highlighting)
  
  saveWorkbook(df, file = "Test_Output.xlsx", overwrite =  TRUE)
  </code></pre>
  
  <p>In the above code, I am trying to highlight any cells that contain "Cat" in column A and then highlighting the next two adjacent cells in yellow in columns B and C. </p>
  
  <p>As in the original problem, I will have many columns throughout the spreadsheet so helping me iterate this through all the specific "update" flag columns will be a bonus. I essentially will have to highlight adjacent cells next to "update" text throughout the excel workbook (i.e. B10 = "Update" then highlight C10 &amp; D10, F30 = "Update" then highlight G30 &amp; H30, and so on)</p>
  
  <p>Much thanks in advance for the help!</p>