Advertisement
Guest User

Untitled

a guest
May 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. //Copy a spreadsheet, rename the new one using original name
  2. //Display a toast message once the process has finished
  3. function example1() {
  4. var ss1 = SpreadsheetApp.getActiveSpreadsheet();
  5. var ss1Name = ss1.getName();
  6. ss1.copy(ss1Name + "-example1");
  7. ss1.toast("Spreadsheet copied & named", "Finished", 5);
  8. }
  9.  
  10. //Add an editor and viewers to the new spreadsheet
  11. function example2() {
  12. var originalSs = SpreadsheetApp.openById('1ZI_sgQ3SGbVs4WZwYt6kuMszYFHsngLvtVbnXvvZIwQ');
  13. var ss2 = originalSs.copy("NEW"); //Normally don't include this line
  14. ss2.rename("example2");
  15. ss2.addEditor('brgablog2@gmail.com');
  16. ss2.addViewers(['brgablogse@gmail.com', 'brgablogesp@gmail.com']);
  17. }
  18.  
  19. //Move a specific sheet to a new location
  20. function example3() {
  21. var currentSs = SpreadsheetApp.getActiveSpreadsheet();
  22. var ss3 = currentSs.copy("example3");
  23. var sheetAll = ss3.getSheetByName("All");
  24. sheetAll.activate();
  25. ss3.moveActiveSheet(5);
  26. }
  27.  
  28. //Move a sheet to a new location using getNumSheets
  29. function example4() {
  30. var currentSs = SpreadsheetApp.getActiveSpreadsheet();
  31. var ss4 = currentSs.copy("example4");
  32. var sheetAll = ss4.getSheetByName("All");
  33. sheetAll.activate();
  34. var numOfSheets = ss4.getNumSheets();
  35. ss4.moveActiveSheet(numOfSheets);
  36. }
  37.  
  38. //Insert a new sheet and delete a sheet
  39. function example5() {
  40. var currentSs = SpreadsheetApp.getActiveSpreadsheet();
  41. var ss5 = currentSs.copy("example5");
  42. var numOfSheets = ss5.getNumSheets();
  43. ss5.insertSheet(numOfSheets);
  44. var firstSheet = ss5.getSheets()[0];
  45. ss5.deleteSheet(firstSheet);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement