google-apps-script - 更改 googlescript 中文件夹的名称?
问题描述
亲爱的,我有一个制作响应输出文件夹“ MURAD ”的表格,我想将此MURAD更改为“ rowContents
”
在哪里
var rowContents=sheet.getRange(lastRow,1,1,sheet.getLastColumn()).getValues()
;
脚本是
function myFunction() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getActiveSheet();
var lastRow=ss.getLastRow();
//the first column contains the timestamp
var department=sheet.getRange(lastRow,2).getValue();
//----------------------------------------------------------------------
var subjectCode=sheet.getRange(lastRow,3).getValue();
var courseCode=sheet.getRange(lastRow,4).getValue();
var courseNo=sheet.getRange(lastRow,5).getValue();
//var newResponse=subjectCode.toString()+"-"+courseCode.toString()+"-"+courseNo.toString();
//here the new column with the file name is going on
var newResponse=courseCode.toString()+courseNo.toString();
//-----------------------------------------------------------------------
sheet.getRange(lastRow,7).setValue(newResponse);
var secodarySheetId;
switch(department) {
case "Physics":
secodarySheetId="1k2rOZfXjXHciPQh1pXn7-GP-p3rccMgT";//Paste here the Id of the destinationsheet in the Physics folder
break;
case "Chemistry":
secodarySheetId="16-TOKctf8Y7nHyYFK8OgNIMCd9YQFvRT";//Paste here the Id of the destinationsheet in the Chemistry folder
break;
case "Math":
secodarySheetId="1aPXI357UfQGdJnoxYfvtSq7GXhfizSSC";//Paste here the Id of the destinationsheet in the Maths folder
break;
}
// var files=DriveApp.getFolderById(secodarySheetId).getFiles();
//while(files.hasNext())
//{
// Logger.log(files.next())
//}
//DriveApp.createFolder(secodarySheetId)
var rowContents=sheet.getRange(lastRow,1,1,sheet.getLastColumn()).getValues();
var folders = DriveApp.getRootFolder().searchFolders('AlulaCR');
while (folders.hasNext()) {
var folder = folders.next();
Logger.log(folder.getName());
}}
解决方案
尝试这样的事情:
function changeFolderName(oldName) {
var oldName=oldName||"MURAD";
var folders=DriveApp.getFoldersByName("MURAD");
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rowContents=sh.getRange(sh.getLastRow(),1,1,sh.getLastColumn()).getValues()[0];
var n=0;
while(folders.hasNext()) {
var folder=folders.next();
n++;
}
if(n==1 && rowContents[?]) {//dont know which one you want
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
folder.setName(rowContents[?]);//Dont know which one you want
}else{
SpreadsheetApp.getUi().alert("Need Help. Found more than one folder with that name or invalid new name.");
}
}
推荐阅读
- powershell - Solr 7.3.1 不会启动“SSL_PORT_PROP”此时出乎意料
- python - 解析电子邮件正文
- php - 通过 PHP 从 URL 读取我是否被 PWNED JSON 值
- redux - 如果发生令牌刷新,则重新启动 API 请求队列
- forms - 如何获取 vue treeselect 值
- c# - 我们可以从单个 TFS 构建中触发多个代理/侦听器吗
- javascript - 如何在谷歌图表上实现 3d 饼图?
- python - 从稀疏数据创建 python 列表推导
- tensorflow.js - Tensorflow.js 可以用于人脸识别吗?
- c# - 为什么 C# VS2017 智能感知不能与 var 和本地函数一起使用?