Hi all,
I was hoping someone could help me tweak this script please that I've found from others.
The aim is to combine data from multiple tabs in multiple workbooks into one new workbook in Google Sheets.
This currently works but only takes the first tab from each workbook, I would like to take all tabs.
function combineRevitSchedules() {
var folder = DriveApp.getFolderById("changedforsecurity");
var filesIterator = folder.getFiles();
var file;
var fileType;
var ssID;
var combinedData = [];
var data;
while(filesIterator.hasNext()){
file = filesIterator.next();
fileType = file.getMimeType();
if(fileType === "application/vnd.google-apps.spreadsheet"){
ssID = file.getId();
data = getDataFromSpreadsheets(ssID);
data = data.map(function(r) { return r.concat([file.getName()]); });
combinedData = combinedData.concat(data);
} //if ends here
} //while ends here
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Combined");
ws.getRange("A2:G").clearContent();
ws.getRange(2,1, combinedData.length, combinedData[0].length).setValues(combinedData);
}
function getDataFromSpreadsheets(ssID){
var ss = SpreadsheetApp.openById(ssID);
var ws = ss.getSheets()[0]; //this line currently returns only one tab
var data = ws.getRange("B3:E" + ws.getLastRow()).getValues();
return(data);
}
I can't quite work out how to change the getSheets to return more than one sheet without an error.
Any help would be appreciated, I'm still learning my way around.
Thank you!