I am using openpyxl to read excel file.
For my application, i need to read the background color of the cell in the xlsx file But i cant find how to load those color info.
I tried to use cell.style.fill.color.index, but it only return FFFFFFFF as background which is not correct to the file i read.
Does openpyxl support reading color format?
I updated openpyxl to v. 2.2. They seem to have resolved the problem that I documented in my original answer (see below). I am now able to successfully retrieve the background color after I've set it manually through Excel. However, the syntax has changed slightly:
somecell.fill.start_color.index
I experimented with this and noticed that if I set the background color via openpyxl like this:
_cell.style.fill.fill_type = Fill.FILL_SOLID
_cell.style.fill.start_color.index = Color.DARKGREEN
then retrieve the value like this:
_style.fill.start_color.index
then I get the correct response:
'FF008000'
However, if I set the background color in Excel and save the file, then access it via openpyxl, then I get the same thing you did:
'FFFFFFFF'
So, the upshot seems to be that opepyxl styles are still unreliable. See my comment, under the question, with a link to the comment from the author of openpyxl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With