I've been experiencing issues using openpyxl to read in a cell color from excel as a hexidecimal. I've been looking around a lot and ultimately I'm thinking that there is no direct way of reading any color into python from excel using openpyxl. Here's how I'm doing it:
from openpyxl import load_workbook
wb = load_workbook('test.xlsx',data_only=True)
sh = wb['Sheet1']
cell = 'A2'
rgb = sh[cell].fill.start_color.rgb
This spits out rgb sometimes when I'm using certain colors, and often gives incorrect colors. I'm guessing that this is basing the rgb color on the built on color index (seen here. is there any way around this to get essentially any color's rgb from a cell and not just a handful?
Thanks, Kevin
update here's what I get as an output when I set the cell as any fill color from the "fill color" button on the Font tab on excel (in this case, it is Gray- 25%, Background 2):
"Values must be of type (type 'basestring')".
I ended up realizing that it does in fact work when I change the color of the cell using the Styles tab on excel (i.e. the "bad", "good", "neutral" style) to color the cell, but this isn't convenient as it isn't able to get as many specific colors in excel.