469,649 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

PyExcelerator: how to set colours?

I'd like some cell to be a Blue "ABCDE".

Here's come code thatv tries various values for pattern_for_colour and
font.colour_index, to no avail.

Can anyone suggest the right way to set colours?

Thanks!

Gerry

======================

from pyExcelerator import *

w = Workbook()
ws = w.add_sheet('alpha')

style = XFStyle()
fore_colour = style.pattern.pattern_fore_colour
back_colour = style.pattern.pattern_back_colour

ws.write (1, 1, "fore_colour")
ws.write (1, 2, fore_colour)

ws.write (2, 1, "back_colour")
ws.write (2, 2, back_colour)

text = "ABCDE"

row = 5

for offset in range(-32,512):

row += 1

style.font.colour_index = fore_colour + offset

ws.write(row,3, fore_colour + offset, style)

ws.write(row,5,text, style)

style.pattern.pattern_fore_colour = fore_colour + offset

ws.write(row,6,text, style)

w.save('test.xls')

=====================

shows no colour variation for any of these values of offset.

Dec 22 '06 #1
1 4213

Gerry wrote:
I'd like some cell to be a Blue "ABCDE".

Here's come code thatv tries various values for pattern_for_colour and
font.colour_index, to no avail.

Can anyone suggest the right way to set colours?

Thanks!

Gerry

======================

from pyExcelerator import *

w = Workbook()
ws = w.add_sheet('alpha')

style = XFStyle()
fore_colour = style.pattern.pattern_fore_colour
back_colour = style.pattern.pattern_back_colour

ws.write (1, 1, "fore_colour")
ws.write (1, 2, fore_colour)

ws.write (2, 1, "back_colour")
ws.write (2, 2, back_colour)

text = "ABCDE"

row = 5

for offset in range(-32,512):

row += 1

style.font.colour_index = fore_colour + offset

ws.write(row,3, fore_colour + offset, style)

ws.write(row,5,text, style)

style.pattern.pattern_fore_colour = fore_colour + offset

ws.write(row,6,text, style)

w.save('test.xls')

=====================

shows no colour variation for any of these values of offset.
Is this what you were after?
--------------------------------------------------------------
from pyExcelerator import *

w = Workbook()
ws = w.add_sheet('boo')

style = XFStyle()
fore_colour = style.pattern.pattern_fore_colour
back_colour = style.pattern.pattern_back_colour

ws.write (1, 1, "fore_colour")
ws.write (1, 2, fore_colour)

ws.write (2, 1, "back_colour")
ws.write (2, 2, back_colour)

text = "ABCDE"

row = 5

for offset in range(-32,512):
row += 1

fnt = Font()
fnt.colour_index = fore_colour + offset
style.font = fnt
ws.write(row, 3, offset, style)
ws.write(row, 5, text, style)

p = Pattern()
p.pattern_fore_colour = fore_colour + offset
p.pattern = style.pattern.SOLID_PATTERN
style.pattern = p
ws.write(row, 6, text, style)

w.save('test.xls')
--------------------------------------------------------------------------------

Waldemar

Dec 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marco Aschwanden | last post: by
2 posts views Thread by tkpmep | last post: by
reply views Thread by Jens Kabella | last post: by
5 posts views Thread by susan | last post: by
3 posts views Thread by tkpmep | last post: by
1 post views Thread by aneesh.goel.rbtx | last post: by
1 post views Thread by patrick.waldo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.