Silly, fun and useful things to do with Resolver One
  • HOME
  • About
  • Articles
  • Fun
  • Snippets
  • Disclaimer
  • Useful Links

Site by Voidspace

Email Michael

Download Resolver One

RSS Feed RSS Feed

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.

Site Built with rest2web

Creative Commons License

IronPython Wiki

IronPython in Action IronPython in Action

Coloring Alternate Rows

Resolver in Action

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.

  • Download the Colored Rows Spreadsheet

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):

def ColorAlternateRows(cellRange, mainColor=Color.CornflowerBlue, alternateColor=None):
    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:

sheet = workbook['Sheet1']

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)


Hosted by Webfaction

Return to Top

Last edited Mon Dec 10 21:27:49 2007.

Copyright ©2007 Michael Foord. All rights reserved. Design by Elemental Works. Logo by FuchsiaShock. Valid XHTML & CSS.

This work is licensed under a Creative Commons License.