Skip to content

Instantly share code, notes, and snippets.

@lutfiihsan
Forked from mhawksey/gist:2252211
Created April 10, 2020 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lutfiihsan/7fbc3b3b6c814900d8538fd03d4acdb7 to your computer and use it in GitHub Desktop.
Save lutfiihsan/7fbc3b3b6c814900d8538fd03d4acdb7 to your computer and use it in GitHub Desktop.
Google Apps Script to combine data from different sheets (used in http://mashe.hawksey.info/?p=13130)
function combineData(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheets = doc.getSheets(); // get all the sheets
var outSheet = doc.getSheetByName("combined"); // set where we want to write the results
for (i in sheets){ // loop across all the sheets
if (sheets[i].getSheetName().substring(0,9) == "followers"){ // if sheetname starts with 'follower' then
var target = sheets[i].getSheetName().substring(12); // extract users name for target column
var data = getRowsData(sheets[i]); // get extisting data from current sheet
for (j in data){
data[j]["target"] = target; // create a target column with the users name
}
insertData(outSheet, data); // insert data in 'combined' sheet
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment