Skip to content

Instantly share code, notes, and snippets.

@cryptoquick
Created September 29, 2014 07:06
Show Gist options
  • Save cryptoquick/7d1c70103e4ef0181db9 to your computer and use it in GitHub Desktop.
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.
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