how to translate theme color to an RGB value

1,428 views
Skip to first unread message

derksen...@gmail.com

unread,
Dec 10, 2015, 2:47:58 PM12/10/15
to openpyxl-users
Hi, 

just started to play with openpyxl. I'm trying to get the cell colors for a sheet i'm parsing. I'm fine on the indexed colors, however i struggle to translate the themed colors to an RGB value.

I.e. the color object contains: 
Color(rgb=Values must be of type <type 'basestring'>, indexed=Values must be of type <type 'long'>, auto=Values must be of type <type 'bool'>, theme=6, tint=0.399975585192, type='theme')

And i need to find a way to translate theme and tint to a color.. 

I came across 


which addressed same problem, but the solution there doesn't work anymore in more recent openpyxl. 

Hopefully there's a straightforward way to do this? 

Tx,
-Daniel

Charlie Clark

unread,
Dec 10, 2015, 2:59:46 PM12/10/15
to openpyx...@googlegroups.com
Am .12.2015, 20:47 Uhr, schrieb <derksen...@gmail.com>:

> just started to play with openpyxl. I'm trying to get the cell colors
> for a
> sheet i'm parsing. I'm fine on the indexed colors, however i struggle to
> translate the themed colors to an RGB value.

Struggle you will. This is from the specification:

"""
A zero-based index into the <clrScheme> collection (§20.1.6.2),
referencing a particular <sysClr> or <srgbClr> value expressed in the
Theme part. The possible values for this attribute are defined by the W3C
XML Schema unsignedInt datatype.
"""
Internally openpyxl doesn't use any themes but it does come with a default
one that always gets written. See openpyxl/writer/theme.py for detail. The
workaround suggested by Adam back in 2013 for working with a particular
scheme should basically still work.

Hope that helps.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

williaml...@gmail.com

unread,
Jan 12, 2018, 9:39:05 AM1/12/18
to openpyxl-users
I stumbled upon this issue, as I faced the exact same problem parsing excel files. For all the ones interested, indeed the posted link works, but needs different imports:  Now QName and fromstring need to be imported from openpyxl.xml.functions . Hope this tip will help you.
Bill
Reply all
Reply to author
Forward
0 new messages