title: How can I get the text by color from a word document with win32com?
body: <p>I have a word document with several tables. In each table there are two colors, black and red.</p>
  
  <p>I'd like to get the text from cells in a word document table by its color. I found a way, but I think it's very inefficient.</p>
  
  <p>The following code gets the text from a word table cell, and prints each word with it's color.</p>
  
  <pre class="lang-py prettyprint-override"><code>import os, sys
  import win32com.client, re
  
  path = os.path.join(os.getcwd(),"../files/tests2.docx")
  word = win32com.client.Dispatch("Word.Application")
  word.Visible = 1
  doc=word.Documents.Open(path)
  
  for table in doc.Tables:
      f = 2
      c = 2
      wc = table.Cell(f,c).Range.Words.Count
      for i in range(1,wc):
          print table.Cell(f,c).Range.Words(i), table.Cell(f,c).Range.Words(i).Font.Color
  </code></pre>
  
  <p>Do you know any other (better) way to achieve this? </p>
  
  <p>Thank you.</p>