Home > Software design >  How to get all sheets by openById while standalone
How to get all sheets by openById while standalone

Time:08-20

I am trying to make a standalone script to action for another spreadsheet. It's working for 1st sheet only but it's not working for all sheets.

 function doSomething(){
    var ssID = "123abc";
    var ss = SpreadsheetApp.openById(ssID);
    var sheet = ss.getActiveSheet(); //var sheet = ss.getActiveSpreadsheet().getSheets(); I tried it also, but giving error.         
    var range = sheet.getRangeList(['A3:A','D3:D']);
    range.setFontFamily("Arial");
    //Rest do something
    }
    

I need an example to work all sheets and need work all except individual sheets.

CodePudding user response:

If you want to loop through all the sheets and set the font for the range it can be done this way:

function doSomething(){
  var ssID = "123abc";
  var ss = SpreadsheetApp.openById(ssID);
  var sheets = ss.getSheets();
  var sheets_to_skip = ['aaa', 'bbb']; // names of the sheets you want to skip

  sheets.forEach(sheet => {
    if (!sheets_to_skip.includes(sheet.getName())) {
      var range = sheet.getRangeList(['A3:A','D3:D']);
      range.setFontFamily("Arial");
    }
  })
}
  • Related