Always a solution out there, somewhere in the deep ocean of SO:
def getBGColor(book, sheet, row, col):
xfx = sheet.cell_xf_index(row, col)
xf = book.xf_list[xfx]
bgx = xf.background.pattern_colour_index
pattern_colour = book.colour_map[bgx]
#Actually, despite the name, the background colour is not the background colour.
#background_colour_index = xf.background.background_colour_index
#background_colour = book.colour_map[background_colour_index]
return pattern_colour
Oh, wait. this is even better!
EDIT:
Here is a complete code:
from xlrd import open_workbook
wb = open_workbook('cel_lis.xls', formatting_info=True)
sh = wb.sheet_by_name('Sheet1')
def getBGColor(book, sheet, row, col):
xfx = sheet.cell_xf_index(row, col)
xf = book.xf_list[xfx]
bgx = xf.background.pattern_colour_index
pattern_colour = book.colour_map[bgx]
#Actually, despite the name, the background colour is not the background colour.
#background_colour_index = xf.background.background_colour_index
#background_colour = book.colour_map[background_colour_index]
return pattern_colour
print("The RGB value of the cell is: {}".format(getBGColor(wb, sh, 0, 0)))
OUTPUT:
The RGB value of the cell is: (255, 0, 0)
Note:
I used a worksheet of type .xls
with a name cel_lis.xls
having its
sheet called Sheet1
with the first cell A
which has a Red
background color.

EDIT 2:
To get the name
of the color, you could use webcolors
:
from webcolors import rgb_to_name
rgb_Col = getBGColor(wb, sh, 0, 0)
print("The RGB value of the cell is: {} which is equivalent to {}".format(rgb_Col, rgb_to_name(rgb_Col)))
OUTPUT:
The RGB value of the cell is: (255, 0, 0) which is equivalent to red