PyExcelerator: how to set colours?

G

Gerry

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.
 
W

Waldemar Osuch

Gerry said:
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')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top