Использование xlrd
:
from xlrd import open_workbook
from webcolors import rgb_to_name
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
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
Примечание:
Я использовал лист типа .xls
с именем cel_lis.xls
, имеющий его
лист с именем Sheet1
с первой ячейкой A
с фоном Red
цвет.