Alternating row color using xlsxwriter in Python 3
<p>Has anybody implemented alternating row color while generating excel using xlsxwriter in Python3?</p>

<pre><code>data_format = workbook.add_format(
    {
        'bg_color': '#FFC7CE'
    })

worksheet.write(data_row, data_col + 1, row[1], data_format)
</code></pre>

<p>This sets the color for each column.</p>

<p>There is nothing stopping you from setting the formats manually as follows:</p>

<pre><code>import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

data_format1 = workbook.add_format({'bg_color': '#FFC7CE'})
data_format2 = workbook.add_format({'bg_color': '#00C7CE'})

for row in range(0, 10, 2):
    worksheet.set_row(row, cell_format=data_format1)
    worksheet.set_row(row + 1, cell_format=data_format2)
    worksheet.write(row, 0, "Hello")
    worksheet.write(row + 1, 0, "world")

workbook.close()
</code></pre>

<p>This would give you output looking as follows:</p>

<p><a href="http://i.stack.imgur.com/qCjSM.png" rel="nofollow"><img src="http://i.stack.imgur.com/qCjSM.png" alt="Alternating row colours"></a></p>

python python-3.x xlsxwriter