I have a word document with several tables. In each table there are two colors, black and red.
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.
The following code gets the text from a word table cell, and prints each word with it's color.
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
Do you know any other (better) way to achieve this?
Thank you.