Something like this should solve your problem:
function onEdit() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var actCell = sheet.getActiveCell();
var actData = actCell.getValue();
var actRow = actCell.getRow();
if (actData != '' && actRow != 1) //Leaving out empty and header rows
{
range.getCell(actRow, 2).setBackground(actData);
}
}
Although, this only colors one cell at a time, but it portrays how you can set a background color based on cell input. Depending on your use case, whether you are copy-pasting multiple hex codes at a time or whether you have an existing list of hexcodes and you would like to show their color against those, using getCell(row,column).setBackground(String)
should be able to help you out.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…