Resolver Hacks contains information and code for doing fun and useful things with Resolver One. This site is created and maintained by Michael Foord, not by Resolver Systems. Please read the disclaimer before using any of the code on this site.
Coloring Alternate Rows

Apparently, when you have a grid of data, wanting to color alternate rows differently is common. It makes it easier to read, or something like that. As always this is easy to do in Resolver.
This is a function, that you pass a spreadsheet to - and can also specify the colors for alternating rows if you don't like the defaults that I've set (no coloring for the 'main' rows and cornflower blue for the alternate ones):
for i in range(1, cellRange.MaxRow + 1):
thisRow = cellRange.Rows[i]
if cellRange.HeaderRow is not None and cellRange.HeaderRow.Top == thisRow.Top:
# Skip header row
continue
if i % 2 and alternateColor is not None:
thisRow.BackColor = alternateColor
elif not i % 2 and mainColor is not None:
thisRow.BackColor = mainColor
The function checks for the header row, to make sure that it doesn't color that.
The example spreadsheet creates and formats a cell range, and then calls ColorAlternateRows:
cellRange = CellRange(sheet.Cells.B4, sheet.Cells.G14)
cellRange.HeaderRow = cellRange.Rows[1]
cellRange.HeaderCol = cellRange.Cols[1]
cellRange.HeaderRow.Bold = True
cellRange.HeaderCol.Bold = True
cellRange.BorderTop = True
cellRange.BorderRight = True
cellRange.HeaderCol.BorderLeft = True
cellRange.Rows[cellRange.MaxRow].BorderBottom = True
ColorAlternateRows(cellRange)
Last edited Mon Dec 10 21:27:49 2007.

IronPython in Action