问题
These two scripts are incredibly slow. I work with a data set of about 32 columns by 1000 rows ( growing pretty rapidly ).
I've read and even used code for treating data like an array so that you can make only one call to google-services, but I'm not sure how that can help me with this case.
I need to hide certain columns depending on which person is using the google sheet
Here is the actual code:
function HideColumns(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("A1");
sheet.hideColumn(range);
range = sheet.getRange("C1:E1");
sheet.hideColumn(range);
range = sheet.getRange("G1");
sheet.hideColumn(range);
range = sheet.getRange("I1");
sheet.hideColumn(range);
range = sheet.getRange("K1");
sheet.hideColumn(range);
range = sheet.getRange("Q1:Z1");
sheet.hideColumn(range);
range = sheet.getRange("AC1:AG1");
sheet.hideColumn(range);
}
function ShowColumns(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("A1");
sheet.unhideColumn(range);
range = sheet.getRange("C1:E1");
sheet.unhideColumn(range);
range = sheet.getRange("G1");
sheet.unhideColumn(range);
range = sheet.getRange("I1");
sheet.unhideColumn(range);
range = sheet.getRange("K1");
sheet.unhideColumn(range);
range = sheet.getRange("Q1:Z1");
sheet.unhideColumn(range);
range = sheet.getRange("AC1:AG1");
sheet.unhideColumn(range);
}
回答1:
For the ShowColumns() script, are you just needing to unhide all columns in the sheet? If so, you could at least simplify that one a bit:
function ShowColumns() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("1:1");
sheet.unhideColumn(range);
}
回答2:
unfortunately hiding columns is a "spreadsheet only" function, no way to make it faster or in batch...
maybe you could imagine a custom UI (built with UiApp or HTMLService) to show only the user relevant data ? but that might not be possible, depending on how much you need spreadsheet specific features..., not speaking of the work it might represent.
来源:https://stackoverflow.com/questions/20131304/optimize-google-script-for-hiding-columns