Last active
January 4, 2016 10:39
-
-
Save gmaclennan/8610640 to your computer and use it in GitHub Desktop.
Google Sheets update cell value from cell colour (hex code)
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
// Will update the value of the cell to the hex value of the color of the cell | |
// It is triggered by typing a "#" into the cell | |
// Unfortunately changing the color of a cell does not trigger an edit event in sheets | |
// Will not work in the new version of Google Sheets | |
function onEdit(e) { | |
var cell, value; | |
var values = e.range.getValues(); | |
for (var i=0; i < values.length; i++) { | |
for (var j=0; j < values[i].length; j++) { | |
value = values[i][j]; | |
if (typeof value === "string" && value.substring(0,1) === "#") { | |
cell = e.range.getCell(i+1, j+1); | |
cell.setValue(cell.getBackground()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See an example: https://docs.google.com/spreadsheet/ccc?key=0ArHJ46D4DMthdGlVaE5pSm9QRWwtX0VoSmN4RGh3T3c&usp=sharing