title: Function to highlight cells using xlwings is slow. How can I speed it up?
body: <p>I have a function within a script which highlights cells in excel books which contain a specified string.</p>
  <p>The functions is:</p>
  <pre><code>def highlight_cell(workbooks, highlight_text):
  with xw.App(visible=False) as app:
      for book in workbooks:
          book = app.books.open(book)
          for sheet in book.sheets:
              sheet = book.sheets(sheet.name)  
              for cell in sheet.used_range:
                  if cell.value == highlight_text:
                      cell.color,  cell.api.Font.Bold  = (255,80, 80), True
          book.save()
  </code></pre>
  <p>The function is called a few times throughout the script.</p>
  <pre><code>highlight_cell([difference_table], &quot;left_only&quot;)
  highlight_cell([types_book], &quot;Incorrect Data Type&quot;)
  highlight_cell([nulls_book], &quot;Non-Nullable - User must change&quot;)
  </code></pre>
  <p>The inputs are a list of workbooks, and a string which appears in the cells to highlight.
  The script creates said workbooks using pandas and openpyxl, having pulled the data from an originating excel book.</p>
  <p>Creating half a dozen workbooks and populating them with the data I want takes all of 2 seconds in total. Highlighting the text with the above function takes about a minute extra. Is this slow time a result of how I structured my function, and can anyone suggest a way to speed it up?</p>