Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

Searching for a Google-apps-script to iterate through a folder of sheets and append a range of data to a consolidated master sheet

My question is about developing a script that will iterate through all google sheets (multiple files) in a folder, capture the data from each sheet file that is on a data consolidation sheet named getdata, and append it to a master sheet named Advisory Master.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Iterating throught all of the Sheets in a Folder

This will iterate through all of the sheets in a folder getting the File Name and the Sheet Name for each sheet and appending it to a sheet named filesSheet.

function iterateSheets() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('filesSheet');
  sh.clear();
  var folder=DriveApp.getFolderById('id');//replace id with actual id of folder
  var files=folder.getFilesByType(MimeType.GOOGLE_SHEETS);
  while(files.hasNext()){
    var file=files.next();
    var ts=SpreadsheetApp.openById(file.getId());
    var allShts=ts.getSheets();
    for(var i=0;i<allShts.length;i++) {
      sh.appendRow([file.getName(),allShts[i].getName()]);
    }
  }
}

With this as a starting point you should be able to consolidate all of your data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...