Skip to content

Instantly share code, notes, and snippets.

@coreysyms
Created June 7, 2017 18:48
Show Gist options
  • Save coreysyms/6a4b11a7e1b443874d79f8d406cfe8cd to your computer and use it in GitHub Desktop.
Save coreysyms/6a4b11a7e1b443874d79f8d406cfe8cd to your computer and use it in GitHub Desktop.
Google Spreedsheet Scripts code
function doGet(e) {
//grab the id passed in of the google ss that I want to duplicate
var id = e.parameter.id;
var name = e.parameter.name;
//get the spreadsheet we want to duplicate and create a new sheet
var duplicateSS = SpreadsheetApp.openById(id);
//copy in the template to the new sheet and name it
var newSheet = duplicateSS.copy(name).getId();
//push the changes we committed above.
SpreadsheetApp.flush();
//get the url of the ss
var returnURL = SpreadsheetApp.openById(newSheet).getUrl();
//if we want to limit people by email and goole account requirements
//SpreadsheetApp.openById(newSheet).addEditor("username@email.com");
//if we want anyone to view with the link
DriveApp.getFileById(newSheet).setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.EDIT);
return ContentService.createTextOutput(returnURL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment