My spreadsheet: Link
I've the following script which is supposed to enable me to control the columns to Hide/Unhide on specific sheets (A,B,C,D,E). There is a trigger on opening the sheet. If I run the script from the Script editor, it does perform the task, sheet after sheet very very slowly. However If I try on opening the spreadsheet, it starts with sheet A, then B, but does not complete it in B. Knowing that currently users are not inputting data, I wonder if this is the best approach (fearing to have at the end a spreadsheet which runs calculations and this script very slowly)
Could you please help with this little task ? I don't know much about writing scripts, this is merely few copy/paste from what I was able to find on the internet,
I appreciate your time!
Basically: I'm trying to control which week to show, I would show week 1 and hide the rest, then the following week, I would show Week 2 and hide the rest, etc...
Script
function hideColumnsOnSheet(sheetName) {
var b = SpreadsheetApp.getActive().getSheetByName(sheetName);
b.showColumns(1, b.getMaxColumns());
b.getRange('4:4')
.getValues()[0]
.forEach(function (r, i) {
if (r && r == 'x') b.hideColumns(i + 1)
});
}
function onOpen() {
hideColumnsOnSheet("A");
hideColumnsOnSheet("B");
hideColumnsOnSheet("C");
hideColumnsOnSheet("D");
hideColumnsOnSheet("E");
}
function onOpen(e)
) are limited in run time to 30 seconds: developers.google.com/apps-script/guides/triggers/#restrictions You should refactor the approach to first develop contiguous ranges of columns that should be hidden and then use whichever of thehideColumns()
methods for those sets of ranges. Currently, you callhideColumns()
once for individual columns, which, as you note, is slow. – tehhowch