I Want a google script that will loop through every workbook(spreadsheet) within my google drive folder, then copying every sheet within to one sheet of my own. I already have a script but its set to copy only the first sheet, could we make it loop to copy all sheets in the spreadsheet
I've tried to change the indexing but it'll only pull one sheet
function getDataToMaster() {
var folder = DriveApp.getFolderById("******************"); //Define id of folder
var contents = folder.getFiles();
var file;
var data;
var sheetMaster = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; //first sheet of the file, change by getSheetByName("NAME") if you want
while(contents.hasNext()){
file = contents.next();
if (file.getMimeType() == "application/vnd.google-apps.spreadsheet") {
var sheet = SpreadsheetApp.openById(file.getId()).getSheets()[0];//first sheet of the file, change by getSheetByName("NAME") if you want
var startRow = 1;
var data = sheet.getDataRange().getValues();
var colToCheck = 7;
for(var j = 0; j < data.length;j++){
if(data[j][colToCheck-1] != "copied"){
sheetMaster.appendRow(data[j]);
sheet.getRange((j+1), colToCheck).setValue("copied");
SpreadsheetApp.flush();
}
}
}
}
}