I have a database that has columns of RGB values and I wanted to display the color on anther column. I will have a custom function on the cell where I passed in the RGB values from the other columns.
=setBGColor(INDIRECT(ADDRESS(ROW(),COLUMN(F2)), INDIRECT(ADDRESS(ROW(),COLUMN(G2)), INDIRECT(ADDRESS(ROW(),COLUMN(H2)))
In the custom function I want to set the background color of the caller cell and also return the hex value. The first problem I ran into is that I couldn't find a decimal to hex conversion function from the Google script. In the spreadsheet there is the handy DEC2HEX
function but I couldn't find it in the script editor.
The second problem is that I don't know how to get the cell that called the function. I tried this and it doesn't work. I tested with some dummy hex value and got an error "You do not have permission to call setBackground".
function setBGColor()
{
//var rgb_hex = "#" + decToHexFunc(r) + decToHexFunc(g) + decToHexFunc(b);
SpreadsheetApp.getActiveSpreadsheet().getCurrentCell().setBackground("FFE4CE"); // test
//return rgb_hex;
}