I'm creating color palettes with Google Sheets as a basis for a color reference book: You can see a sheetproof here. I wanted to batch fill the cells' background in Column C according to the HEX/RGB Codes. Manipulating a script I found elsewhere, I got this:
function Colors_in_RGB_from_HEX() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var lastRow = sheet.getLastRow(); for (var i = 1; i <= lastRow; i++) { var valRgb = sheet.getRange(i, 2).getValue(); sheet.getRange(i, 3).setBackgroundRGB( parseInt(valRgb.substr(1, 2), 16), parseInt(valRgb.substr(3, 2), 16), parseInt(valRgb.substr(5, 2), 16) ); }}The script works but only fills 1,096 cells out of 65,536, due to exceeded maximum execution time error (6 minutes). I asked for help on Reddit, 'cause Idk anything about Apps Script: I limited to copying, correcting and doing various tests with the code above (I'm more familiar with Excel, but it has a limit of colors-per-sheet that strangles me).
They answered me that
the trick, unlike Excel, is that I should never read one cell at atime: instead I should call getRange once on the whole range, thencall getValues and obtain an array with the colors, finally use thesetBakgrounds to set the backgrounds passing the array of colorsobtained as parameters
I've been studying the answer (a brain teaser for me) for about a month, but I've to surrender in front of the evidence that I need someone to write the Apps Script for me.