google apps script - Duplicate a sheet and rename copy to cell value -
i need take spreadsheet, duplicate (there should 2 separate spreadsheet files), , rename copy value of specific cell original spreadsheet.
i did research in google's documentation, looked in stackoverflow. modified found @ "google script copy , rename sheet , name based on cell reference"
function createnewtimesheet() { // code below makes duplicate of active sheet var ss = spreadsheetapp.getactivespreadsheet() spreadsheetapp.getactivespreadsheet().duplicateactivesheet(); // code below rename active sheet date based on cell o49 of source spreadsheet var myvalue = spreadsheetapp.getactivesheet( ).getrange("o49").getdisplayvalue(); spreadsheetapp.getactivespreadsheet().renameactivesheet(myvalue); }
here's problem:
the code snippet above creates copy of original spreadsheet new tab within original (source) spreadsheet , renames tab properly. not need. need original (source) spreadsheet duplicated, not copied, duplicate of original (source) spreadsheet , duplicate 2 separate files, not tab within original (source) file.
i need like: right-click, left-click "make copy", rename "copy of ..." sheet desired name.
refer below code...
function createcopy() { var myvalue = spreadsheetapp.getactivespreadsheet().getactivesheet().getrange("o49").getvalue(); var copiedspreadsheet = spreadsheetapp.getactivespreadsheet().copy(myvalue); }
edit : create copy of spreadsheet , place particular drive folder
function createcopy() { var myvalue = spreadsheetapp.getactivespreadsheet().getactivesheet().getrange("o49").getvalue(); var destinationfolder = driveapp.getfolderbyid("<<drive folder id>>"); driveapp.getfilebyid(spreadsheetapp.getactivespreadsheet().getid()).makecopy(myvalue,destinationfolder); }
Comments
Post a Comment