Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 如何在Google Apps脚本电子表格嵌入脚本中使用确认按钮?_User Interface_Google Apps Script_Google Sheets - Fatal编程技术网

User interface 如何在Google Apps脚本电子表格嵌入脚本中使用确认按钮?

User interface 如何在Google Apps脚本电子表格嵌入脚本中使用确认按钮?,user-interface,google-apps-script,google-sheets,User Interface,Google Apps Script,Google Sheets,我使用此Google Apps脚本向我在电子表格中选择的人发送一封包含请求的电子邮件: function sendRequestEmail() { var data = SpreadsheetApp.openById(SPREADSHEET); if(!employee_ID) { employee_ID = getCurrentRow(); if (employee_ID == 1) { var employee_ID = Browser.inputBox(

我使用此Google Apps脚本向我在电子表格中选择的人发送一封包含请求的电子邮件:

function sendRequestEmail() {
  var data = SpreadsheetApp.openById(SPREADSHEET);
  if(!employee_ID) {
    employee_ID = getCurrentRow();
    if (employee_ID == 1) {
      var employee_ID = Browser.inputBox("Você precisa selecionar um assistido?", "Choose a row or type its number here:", Browser.Buttons.OK_CANCEL);
    }
  }

  // Fetch variable names
  // they are column names in the spreadsheet
  var sheet = data.getSheets()[0];
  var columns = getRowAsArray(sheet, 1);
  Logger.log("Processing columns =" + columns);
  var employeeData = getRowAsArray(sheet, employee_ID); 
  Logger.log("Processing employeeData = " + employeeData);
  // Assume first column holds the name of the person
  var email2Send = "pythonist@example.com";
  var title = "Request by email";
  var name = employeeData[0];  
  var mother_name = employeeData[1];
  var message = "Hi, I have a request for you, " + name + ", this is... example";
  // HERE THE
  // CONFIRMATION BUTTON!!!                     
  MailApp.sendEmail(email2Send, title, message);
  }
在发送电子邮件之前,我需要一个确认按钮,类似这样:

 function showConfirmation(name, email2Send) { 
  var app = UiApp.createApplication().setHeight(150).setWidth(250);
  var msg = "Do you confirm the request to " + email2Send + " about " + name + "?";
  app.setTitle("Confirmation of request");      
  app.add(app.createVerticalPanel().add(app.createLabel(msg)));
  var doc = SpreadsheetApp.getActive();
  doc.show(app);
  }
因此,如果用户按OK,应用程序将执行行
MailApp.sendmail(email2Send,title,message)并发送电子邮件

我不得不承认我的无知。我正在阅读詹姆斯·费雷拉(James Ferreira)的《谷歌应用程序脚本》(Oreilly)一书中关于处理器的第4章。我尝试使用谷歌文档中提供的一个示例(已经删除了代码!)。但我遇到了一个我无法理解的错误

使用的代码如下示例所示:

var ui = DocumentApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);
 // Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) ... DO THIS

在这个简单的项目中,我有一些紧迫感,所以请原谅我在进一步研究答案之前问了这个问题(我在寻找答案的同时也在寻找答案)。那么,我如何在这段代码中使用确认/取消按钮呢?

您展示的代码片段是用于文档嵌入式UI的,电子表格上下文的等效(嗯…几乎)类是
Browser.MsgBox(提示符,按钮)
,请参见文档,它将比创建UI+处理程序函数更简单。。。即使布局和外观是相当基本的,它也是简单而有效的

在您的代码中,它变成:

  ...
  var confirm = Browser.msgBox('send confirmation','Are you sure you want to send this mail ?', Browser.Buttons.OK_CANCEL);
  if(confirm=='ok'){ MailApp.sendEmail(email2Send, title, message)};
  ...

您显示的代码片段是用于文档嵌入式UI的,电子表格上下文的等效(嗯…几乎)类是
Browser.MsgBox(提示符,按钮)
,请参见文档,它将比创建UI+handler函数更简单。。。即使布局和外观是相当基本的,它也是简单而有效的

在您的代码中,它变成:

  ...
  var confirm = Browser.msgBox('send confirmation','Are you sure you want to send this mail ?', Browser.Buttons.OK_CANCEL);
  if(confirm=='ok'){ MailApp.sendEmail(email2Send, title, message)};
  ...