简体   繁体   中英

Naming a New Sheet with Google Scripts from a specific cell on a Google Sheet

trying to figure out how to give a new sheet that is copied into a folder a specific name each time from a button script. The specific name would come from a specific cell each time.

Here's the current code being used and the New Sheet is what I'm trying to have named from cell B3 on a specific spreadsheet each time. No idea how to do this, it just names it NEW SHEET each time and then errors out when I try to do B3.

function cloneGoogleSheet() {
  var destFolder = DriveApp.getFolderById("Folder Name"); 
  DriveApp.getFileById("Folder Name").makeCopy('NEW SHEET', destFolder); 
 SpreadsheetApp.getActive().getSheetByName('NEW SHEET').setName('Specific Sheet!B3')
}

Any help is appreciated!

function cloneGoogleSheet() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const name = sh.getRange('A1').getDisplayValue();
  const destFolder = DriveApp.getFolderById("Folder Id"); 
  DriveApp.getFileById("file id").makeCopy(name, destFolder); 
}

Get used to using file id's and not names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM