How do I output an array to the first sheet in google sheets

Id like to output the list of sheet names obtained from this loop, to the first sheet

var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheetNameArray = [];
  var sheets = ss.getSheets();
  for (var i = 0; i < sheets.length; i++) {


1 answer

  • answered 2018-03-13 22:01 Tanaike

    Is this what you want to do? This script imports sheet names in the opened spreadsheet to the current sheet.

    Flow :

    1. Retrieve sheets from the opened spreadsheet.
    2. Create 2 dimensional array to using setValues().
    3. Import the created data to the current sheet.

    Sample script :

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var sheetNameArray ={return [e.getName()]});
    ss.getActiveSheet().getRange(1, 1, sheetNameArray.length, sheetNameArray[0].length).setValues(sheetNameArray);

    Note :

    • If you want to import the sheet name to a row, please use this var sheetNameArray = [{return e.getName()})]; instead of var sheetNameArray ={return [e.getName()]});

    Reference :

    If I misunderstand your question, I'm sorry.