Reputation: 41
How do I hide some sheets in a spreadsheetApp with googleScript? I have a spreadsheet with multiple sheets, and I want to reduce the spreadsheet to only the first visible sheet and all the other hidden, using googlScript
Upvotes: 4
Views: 12952
Reputation: 1
Will you need hide the pages of g.sheet after you access they using buttons in main page of menu to access to other pages which you want to hide? if that is your problem you should resolve using a simple coding, make one button per page to back to your main page, to the others page always keep hidden, just to the main not keep, for this, use the follow content:
function menu() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var pagetohide = sheet; var menu = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('menu'); SpreadsheetApp.setActiveSheet(menu); pagetohide.hideSheet();
I hope helped you, sorry per my english.
Upvotes: 0
Reputation: 180
I too am looking for that same answer. As far as I can tell SpreadsheetApp, Spreadsheet and Sheet classes dont have any Hide/Unhide methods. However I use the following code to set sheet protection on all sheets in a spreadsheet, to iterate through all sheets and protect them, same could be applied to Hide/UnHide if it is supported.
function protectSheets() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var num_sheets = ss.getNumSheets();
for (var i = 0; i < num_sheets; i++){
SpreadsheetApp.setActiveSheet(ss.getSheets()[i]);
var sheet = SpreadsheetApp.getActiveSheet();
var permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
};
}
google-apps-script google-spreadsheet-api google-spreadsheet
Upvotes: 1