[英]Create new spreadsheet name it by the name of sheet Google Scripts
The function below creates a new spreadsheet from the active sheet.下面的函数从活动工作表创建一个新的电子表格。 It names the file based on Cell A1 currently.它当前基于 Cell A1 命名文件。 I'd like to make it so the name is based on the name of the active sheet given not A1.我想这样做,所以名称基于给定的活动工作表的名称,而不是 A1。 Any suggestions?有什么建议?
function createSheet(){
var sheet = SpreadsheetApp.getActiveSheet(); // Get current active sheet.
var sheet_name = sheet.getRange("A1").getDisplayValue(); // Get the value of cell B1, used to name the new spreadsheet.
var folder = DriveApp.getFolderById("1S4Gwem7PZiryj-eDPLR2jeHALpkuZadV"); // Get the ID of the folder where you will place a copy of the spreadsheet.
var newSS = SpreadsheetApp.create(sheet_name); // create new blank spreadsheet in a root folder
var asFile = DriveApp.getFileById(newSS.getId()); // get new spreadsheet as a file
folder.addFile(asFile); // add this file to destination folder
DriveApp.getRootFolder().removeFile(asFile); // remove a file from root folder
var copiedSheet = sheet.copyTo(newSS); // copy active sheet to new spreadsheet
copiedSheet.setName(sheet_name); // rename copied sheet
newSS.deleteSheet(newSS.getSheetByName('Sheet1')); // remove "Sheet1" sheet which was created by default in new spreadsheet
}
Change改变
var sheet_name = sheet.getRange("A1").getDisplayValue()
to到
var sheet_name + sheet.getName()
I hope this is helpful to you!我希望这对你有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.