By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

PyExcelerator: how to set colours?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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.