0

我正在尝试以与往常相同的方式访问 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]);

  }



}
4

1 回答 1

0

类 UI 无法从 Apps 脚本 IDE 调用,但可以从自定义菜单、对话框或单击附加脚本的图像运行的脚本调用。

于 2018-11-19T22:29:10.440 回答