Python - excel - xlwt: coloring every second line

I will just finish some MYSQL to excel script with xlwt, and I need to color every second line for readability.

I tried this:

row = easyxf('pattern: pattern solid, fore_colour blue')

for i in range(0,10,2):

ws0.row(i).set_style(row)

Alone, this coloring is beautiful, but when I write my lines of data, again white.

Can someone please show me an example: "I lost in encoding: /

Regards.

+3
source share
2 answers

I have ever applied color to strings using a method write().
Does something like this work for you? (adapted from this great example ):

mystyle = easyxf('pattern: pattern solid, fore_colour blue')

for row in data:
    rowx += 1
    for colx, value in enumerate(row):
        if rowx % 2 == 0:
            # apply style for even-numbered rows
            ws0.write(rowx, colx, value, mystyle)
        else:
            # no style for odd-numbered rows
            ws0.write(rowx, colx, value)
+4
source

Source: https://habr.com/ru/post/1748675/


All Articles