我正试图以我一贯的方式访问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不能从应用程序脚本IDE调用,但可以从自定义菜单、对话框或单击附带脚本的图像运行的脚本中调用。