how to read the xlsx color infomation by using openpyxl

余生长醉 提交于 2019-12-03 15:14:41

UPDATE (2014):

I updated 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

ORIGINAL RESPONSE (2012):

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!