Am .12.2015, 22:10 Uhr, schrieb <
bkucz...@ucsb.edu>:
> Hi folks,
Hiya Brandon,
> Thanks for creating this package. It's very helpful.
Glad to hear it!
> But I am new to
> python, and I'm having a hard time understanding the details of how
> styles in existing workbooks are reported.
Join the club! ;-)
> I'm working with a spreadsheet where the author has encoded important
> information using the cell's fill color. I would like to accurately
> determine the both the text color and the fill color (in RGB, ideally)
> and also determine whether either one has been modified from the default.
>
> I assumed default would be "white", but when I execute the following on
> an
> empty cell:
>>>> M = openpyxl.load_workbook(/path/to/file...)
>>>> type(M)
> openpyxl.workbook.workbook.Workbook
>
>>>> c=M.active['A10']
>>>> getattr(c.fill.fgColor, c.fill.fgColor.type)
> '00000000'
>
> it looks like black. The cell in question is empty and unmodified (and
> looks white).
Looks like you're getting the default fill. For pattern fills the type is
important and if this is not set the fill will not be applied.
> So, three questions:
> 1- am I doing the right thing to access the cell's fill color? how is
> fgColor different from bgColor? Is it correct to dereference the
> *Color.type to get the *Color value?
Foreground colour vs. background colour. This makes little sense for a
solid fill but think of a cross-hatched filling.
> 2- how do I interpret *color.type 'theme'? I see a COLOR_INDEX for
> color.type 'index' but nothing for theme.
You'll have to look at the specification:
"""
20.1.6.2 clrScheme (Color Scheme)
This element defines a set of colors which are referred to as a color
scheme. The color scheme is responsible for defining a list of twelve
colors. The twelve colors consist of six accent colors, two dark colors,
two light colors and a color for each of a hyperlink and followed
hyperlink.
The Color Scheme Color elements appear in a sequence. The following
listing shows the index value and corresponding Color Name.
"""
> 3- What should I expect to see in fill for empty cells, so that I can
> accurately detect them?
Not sure what you mean by this. I'd check for empty cells by content but I
suspect you want to check whether the fill.type is not None.
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