Created
September 29, 2014 07:06
-
-
Save cryptoquick/7d1c70103e4ef0181db9 to your computer and use it in GitHub Desktop.
Google Apps Spreadsheet Script for Coloring a cell based on the value it contains, if it's a hex color.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function colorize() { | |
var rows = SpreadsheetApp.getActiveRange(); | |
var numRows = rows.getNumRows(); | |
var values = rows.getValues(); | |
for (var r = 0; r < numRows; r++) { | |
var row = values[r]; | |
for (var c = 0; c < row.length; c++) { | |
var val = row[c]; | |
if (val == '' || val == '#') { | |
continue; | |
} | |
else { | |
if (val.indexOf('#') === 0 && val.length === 7) { | |
rows.getCell(r + 1, c + 1).setBackground(val); | |
} | |
} | |
} | |
} | |
}; | |
function onOpen() { | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var entries = [{ | |
name : "Colorize Selected", | |
functionName : "colorize" | |
}]; | |
spreadsheet.addMenu("Script Menu", entries); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment