Skip to content

Instantly share code, notes, and snippets.

@al-codaio
Created May 20, 2019 16:34
Show Gist options
  • Save al-codaio/bbae27144db5f1f75b76794d6622b3f9 to your computer and use it in GitHub Desktop.
Save al-codaio/bbae27144db5f1f75b76794d6622b3f9 to your computer and use it in GitHub Desktop.
One-way data sync between Google Sheets files
var sourceSpreadsheetID = "TO UPDATE";
var sourceWorksheetName = "TO UPDATE";
var targetSpreadsheetID = "TO UPDATE";
var targetWorksheetName = "TO UPDATE";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
//Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
//var thisData = thisSpreadsheet.getRangeByName("teamBugs");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment