Всегда есть решение где-то в глубоком океане 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
Ой, подожди. это даже лучше!
EDIT :
Вот полный код:
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)
Примечание
Я использовал лист типа .xls
с именем cel_lis.xls
, имеющий его
лист под названием Sheet1
с первой ячейкой A
, которая имеет Red
цвет фона.

РЕДАКТИРОВАТЬ 2 :
Чтобы получить name
цвета, вы можете использовать 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