Script to run on specific sheet

旧巷老猫 提交于 2020-04-14 08:56:13

问题


I have a script that I have been using, but it only works with, as written, the active sheet (pulls a list of documents from the specified directory in Google Drive). How can transform this to run on a specific sheet. The name of the sheet is "Per 7".

function list_all_files_inside_one_folder_without_subfolders(){
  var sh = SpreadsheetApp.getActiveSheet();
  var folder = DriveApp.getFolderById('0B4zzmqQYDRm2flZPRFVWd1FfSGpJTXFmcWlSLXVVTUZJRjNlU3QzTER6aHFsYVEzTDdrS00'); // I change the folder ID  here 
  var list = [];
  list.push(['Name']);
  var files = folder.getFiles();
  while (files.hasNext()){
    file = files.next();
    var row = []
    row.push(file.getName())
    list.push(row);
  }
   sh.getRange(1,1,list.length,list[0].length).setValues(list);
}

回答1:


try changing:

 var sh = SpreadsheetApp.getActiveSheet();

to

 var sh = SpreadsheetApp.getActive().getSheetByName('Per 7');


来源:https://stackoverflow.com/questions/35524955/script-to-run-on-specific-sheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!