简体   繁体   中英

How can I get sheet names in a column

I wonder if someone can tell me how can I change the panel that I obtain with this script and instead getting the names of my sheets in a column of the active sheet. Thanks a lot.

function sheetNames() {
   var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
   var sheets = spreadsheet.getSheets();
   var  string = "Lista de hojas:\n" ;
for ( var s = 0 ; s < sheets.length ; s++)
{
  string += sheets[s].getName()+ "\n";
}
  SpreadsheetApp.getUi().alert(string);
}

How about this sample?

function sheetNames() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = spreadsheet.getSheets();
  var  string = "Lista de hojas:\n" ;
  var sn = [[i.getName()] for each (i in sheets)];
  var str = "";
  var strs = [str += i + "\n" for each (i in sn)];
  spreadsheet.getActiveSheet().getRange(1, 1, sn.length, sn[0].length).setValues(sn);
  SpreadsheetApp.getUi().alert(string + str);
}

This script imports sheet names to column 'A' on the active sheet. And message dialog is opened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM