Skip to content

Instantly share code, notes, and snippets.

@barrieroberts
Created May 25, 2017 08:22
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 barrieroberts/f290d920b669162ef4972c4d38d22091 to your computer and use it in GitHub Desktop.
Save barrieroberts/f290d920b669162ef4972c4d38d22091 to your computer and use it in GitHub Desktop.
//Copy a spreadsheet, rename the new one using original name
//Display a toast message once the process has finished
function example1() {
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var ss1Name = ss1.getName();
ss1.copy(ss1Name + "-example1");
ss1.toast("Spreadsheet copied & named", "Finished", 5);
}
//Add an editor and viewers to the new spreadsheet
function example2() {
var originalSs = SpreadsheetApp.openById('1ZI_sgQ3SGbVs4WZwYt6kuMszYFHsngLvtVbnXvvZIwQ');
var ss2 = originalSs.copy("NEW"); //Normally don't include this line
ss2.rename("example2");
ss2.addEditor('brgablog2@gmail.com');
ss2.addViewers(['brgablogse@gmail.com', 'brgablogesp@gmail.com']);
}
//Move a specific sheet to a new location
function example3() {
var currentSs = SpreadsheetApp.getActiveSpreadsheet();
var ss3 = currentSs.copy("example3");
var sheetAll = ss3.getSheetByName("All");
sheetAll.activate();
ss3.moveActiveSheet(5);
}
//Move a sheet to a new location using getNumSheets
function example4() {
var currentSs = SpreadsheetApp.getActiveSpreadsheet();
var ss4 = currentSs.copy("example4");
var sheetAll = ss4.getSheetByName("All");
sheetAll.activate();
var numOfSheets = ss4.getNumSheets();
ss4.moveActiveSheet(numOfSheets);
}
//Insert a new sheet and delete a sheet
function example5() {
var currentSs = SpreadsheetApp.getActiveSpreadsheet();
var ss5 = currentSs.copy("example5");
var numOfSheets = ss5.getNumSheets();
ss5.insertSheet(numOfSheets);
var firstSheet = ss5.getSheets()[0];
ss5.deleteSheet(firstSheet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment