Create list of all sheet names in Google Apps Scripts

后端 未结 2 1030
陌清茗
陌清茗 2021-01-20 04:37

My goal

I have two spreadsheets, SpreadSheetA and SpreadSheetB.

I am trying to get a list of the names of all the sheets in SpreadSheetA and add it to the

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 04:53

    Try the below...

    function getSheetNamesAndAddToOtherSheet() {
      var spreadSheetAURL = "https://docs.google.com/spreadsheets/d/UNIQUE-ID-HERE/edit"; 
      var spreadSheetsInA = SpreadsheetApp.openByUrl(spreadSheetAURL).getSheets();
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      for (var i = 0; i < spreadSheetsInA.length; i++) {
        sheet.appendRow([spreadSheetsInA[i].getName()])
      }
    }
    

提交回复
热议问题