Perspective Table - Invididual Cell Conditional Formatting

A maybe more maintainable variation, if you ever intend on adding other columns you need to style:

	def cc_msval(v, r, c):
		style_orange = {"backgroundColor": "#F7901D"}
		style_green = {"backgroundColor": "#00AA00"}
		return {
			"value": v.getValueAt(r, c),
			"style": style_orange if v.getValueAt(r, c) < 95 else style_green
		}

	transforms = {
		"CC_msval": cc_msval
	}

	return [
		{
			value.getColumnName(col): transforms.get(value.getColumnName(col), lambda v, r, c: v.getValueAt(r, c))(value, row, col)
			for col in xrange(value.columnCount)		
		}
		for row in xrange(value.rowCount)
	]

You could just make a new function, add it to the transforms dictionary, keyed to your column name. The slightly weird syntax at the end is just a nested comprehension to build the required JSON structure.

1 Like