javascript - 尝试手动运行时“无法从上下文调用 SpreadsheetApp.getUi()”
问题描述
我正在尝试以与往常相同的方式访问 Apps Script 中的 UI 对象,事实上,我使用的代码是我之前已经使用过的重复使用的代码,并且工作正常,由于某种原因,我收到了一条错误消息当我尝试运行我的脚本时说我“无法从该上下文中调用 .getUI()”方法,但这通常在使用触发器时出现,但我不是,我只是从 IDE 运行它。
有谁知道是否有更新或有什么问题?也许我做错了什么?如果是这样,我已经粘贴了下面的代码
function addProject() {
var ui = SpreadsheetApp.getUi();
//var listDepartment = ss.getRangeByName("ref_departments").getValues().filter(String);
// var projectSheet = ss.getSheetByName('Project Overview');
var nameResponse = ui.prompt("What is the name of this project?");
var projectName = nameResponse.getResponseText();
var roleResponse = ui.prompt("How Many Resource/Roles are required for this project?");
var roleCount = parseInt(roleResponse.getResponseText());
// var validateDepartment = SpreadsheetApp.newDataValidation()
// .requireValueInList(listDepartment)
// .build();
// var color = ss.getRangeByName("refColor").getValue();
var lastRow = projectSheet.getLastRow();
var lastCol = projectSheet.getMaxColumns();
projectSheet.getRange(lastRow+1, 1)
.setValue(projectName)
.setVerticalAlignment("middle")
.setHorizontalAlignment("Center")
.setFontSize(16)
.setWrap(true)
.setFontWeight("bold")
.copyTo(projectSheet.getRange(lastRow+2, 1, roleCount-1, 1));
projectSheet.getRange(lastRow+1, 2, roleCount, 1).setDataValidation(validateDepartment);
projectSheet.getRange(lastRow+1, 1, roleCount,lastCol).setBackground(color);
var rowPos = lastRow + 1;
// projectSheet.getRange(lastRow+1, 6).setFormula('=if(D'+rowPos+'="","-",if(counta(G'+rowPos+':KV'+rowPos+')<D'+rowPos+',D'+rowPos+'-counta(G'+rowPos+':KV'+rowPos+'),"Full Allocation"))')
// .copyTo(projectSheet.getRange(lastRow+2,6,roleCount-1,1));
//
projectSheet.getRange(lastRow+roleCount+1, 1).setValue("-");
// if( color == "#efefef")
// {
// ss.getRangeByName("refColor").setValue("#ffffff")
// }
// else ss.getRangeByName("refColor").setValue("#efefef");
//
/* Project Name */ variablesSheet.getRange(variablesSheetLastRow+1,1).setValue(projectName);
/* Start Cell*/ variablesSheet.getRange(variablesSheetLastRow+1,2).setValue(projectSheet.getRange(lastRow+1, 1).getA1Notation());
/*End Cell */ variablesSheet.getRange(variablesSheetLastRow+1,3).setValue( projectSheet.getRange(lastRow+1+roleCount, 1).getA1Notation());
/* Number of Jobs */ variablesSheet.getRange(variablesSheetLastRow+1,4).setValue(roleCount);
/* Date Cell */ variablesSheet.getRange(variablesSheetLastRow+1,5).setValue(projectSheet.getRange(lastRow, 7).getA1Notation());
}
function staffHeaders(){
var ss = SpreadsheetApp.getActive();
var utilSheet = ss.getSheetByName("Staff Utilization");
var staffNames = ss.getRangeByName("ref_staff").getValues().filter(String);
utilSheet.getRange(1,1,1,utilSheet.getMaxRows()).clearContent();
for (i = 1; i< staffNames.length ; i++)
{
utilSheet.getRange(1, i+1).setValue(staffNames[i]);
}
}
解决方案
类 UI 无法从 Apps 脚本 IDE 调用,但可以从自定义菜单、对话框或单击附加脚本的图像运行的脚本调用。
推荐阅读
- javascript - Gremlin Javascript 折叠、合并和展开
- javascript - 带有 HTML 文件的 Node.js 子进程
- java - 这段代码中“this”的实例是什么意思?
- java - 与等效的日历代码相比,生成的 java.time 代码是否具有更多代码语句
- xslt-2.0 - 如何从 x:expect 结果中删除 test:ws 元素在 XSpec
- java - 为什么在使用三元 if/else 运算符时增量运算符 (++/--) 不起作用?
- php - 通过 Web 套接字服务器与特定用户 [Android 设备] 连接
- javascript - 使用 ajax 将点击计数发送到 django 视图
- java - Firebase 实时数据库:有没有办法避免在删除值时调用 onDataChange?
- sap - 如何使用 SAP Fiori Client Android App 访问 SAP Fiori Launchpad?引发 SSL 错误