我需要将模板电子表格复制到文件夹,然后在新副本中写入C3。
//get template
var SStemplate = "URL here";
var SStocopy = SpreadsheetApp.openByUrl(SStemplate);
//set destination folder
var SSdestFolder = DriveApp.getFolderById("0B-hjh1DycmoweEl5ZmgxdFBRYzg");
//copy template to destination
DriveApp.getFileById(SStocopy.getId()).makeCopy(name, SSdestFolder);
创建副本后,如何激活它以设置单元格C3的值?
这是最终的工作版本:
function newprojectdocuments(){
//activate current sheet to get new project ID
var trackerss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = trackerss.getSheetByName('AutoTracker');
var range = sheet.getRange('F1:F1');
var foldername = range.getValues();
if( foldername.toString().length === 7 ){
//get template spreadsheet to make copy
var SStemplate = "url";
var SStocopy = SpreadsheetApp.openByUrl(SStemplate);
//set destination folder for new project spreadsheet
var SSdestFolder = DriveApp.getFolderById("ID");
//copy template to the spreadsheet folder
var newFile = DriveApp.getFileById(SStocopy.getId()).makeCopy(foldername,
SSdestFolder);
//open the new file
var ss = SpreadsheetApp.openById(newFile.getId());
var sheet = ss.getSheetByName('Overview');
//Write the value you want in C3 cell
sheet.getRange("C3").setValue(foldername);
//create new folder in deal documents folder
var dealfolder=DriveApp.getFolderById("ID");
var newfolder=dealfolder.createFolder(foldername)
if( foldername.toString().length === 7 ){
Browser.msgBox( "Project " + foldername + " folder & spreadsheet created!
Refresh the tracker to display." )
}
} else {
Browser.msgBox('Project ID must be 7 digits: YYMMDDN format')
}
}