Google script to Save open Sheet to file -


i'm in process of learning google scripts , javascripts, love coding solutions need know lot more apologies being little slow.

i know how use script in google docs not sure yet on how construct many things, learning examples , trying understand find.

i have scenario have google sheet use template user can enter in data in fields click button save whole sheet file (the same going file > save as) use id number in field name of document when saving , place these in folder within same directory master template. after clicking save button sheet need reset original ready entry.

the user can open saved document , make changes if required.

i haven't been able find examples can quite understand make them work assistance great, pointers resources make easier me learn

thanks.

first @ all, create folder in drive named mytargetfolder. put template spreadsheet in, fill "id" first row filed, number value second row.

all script need below :

// create custom menu add save feature.    function onopen() {   var ui = spreadsheetapp.getui();   ui.createmenu('feature')     .additem('save spreadsheet', 'savespreadsheet')     .addtoui(); } 

then implement save feature.

function savespreadsheet() {    var thisspreadsheet = spreadsheetapp.getactive();    /*    first row , second row :          -----         | id  |          -----         | 123 |          -----   */   var id = thisspreadsheet.getactivesheet().getrange(2, 1, 1, 1).getvalue();    var folders = driveapp.getfolders();   var destfolder = '';   while (folders.hasnext()) {     var folder = folders.next();     if ( folder.getname() == 'mytargetfolder' ) {       destfolder = driveapp.getfolderbyid(folder.getid());      }   }    driveapp.getfilebyid(thisspreadsheet.getid()).makecopy(id, destfolder);     // recover template   thisspreadsheet.getactivesheet().getrange(2, 1, 1, 1).setvalue(' ');    spreadsheetapp     .getui()     .alert('check drive make sure file have been saved'); } 

all google app script api spreadsheet documented here.

and api drive.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -