繁体   English   中英

使用Google Apps脚本的确认消息框

[英]Confirmation Message Box Using Google Apps Script

我已经实现了Google Apps脚本代码来显示确认消息,我成功地使用了标签显示了该消息,但是我试图在一个框中而不是标签中显示确认消息,以便用户可以清楚地看到他们提交了文件成功,可以单击该框中的“确定”按钮。 我尝试使用以下代码实现此目标,但显示以下错误消息:

“遇到的错误:只能从绑定到新版Google表格的脚本中调用SpreadsheetApp.getUi()。”

这是我创建的用于编写Google Apps脚本代码的新Google Spreadsheet,但是我复制并粘贴了现有代码。

这是我尝试用来显示确认消息框的代码(上面显示了错误消息):

var ui = SpreadsheetApp.getUi();
   var userChoice = ui.alert(
      'Thank You for uploading files',
      ui.ButtonSet.OK);
   if (userChoice == ui.Button.OK) {
      ui.alert('Operation Confirmed.');
   } else {
      ui.alert('Operation Halted.');
   }

以下是我成功在标签中显示确认消息的代码:

// Create form to hold the file upload buttons for choosing a file and uploading

var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
  var formContent = app.createVerticalPanel();
  form.add(formContent);
  formContent.add(app.createLabel('All of the following files must be submitted prior to completing the form').setHeight('25px').setStyleAttributes(_lbl).setStyleAttribute('font-size','20px'));


  formContent.add(app.createLabel('Reference Letter').setHeight('20px').setStyleAttributes(_lbl));
  formContent.add(app.createFileUpload().setName('Reference'));
  formContent.add(app.createLabel('Reference Letter 2').setHeight('20px').setStyleAttributes(_lbl));
  formContent.add(app.createFileUpload().setName('Reference2'));
  formContent.add(app.createLabel('Reference Letter 3').setHeight('20px').setStyleAttributes(_lbl));
  formContent.add(app.createFileUpload().setName('Reference3'));

formContent.add(app.createSubmitButton('Submit File Uploads'));

function doPost(e) {
  // data returned is a blob for FileUpload widget
  var fileBlob = e.parameter.Reference;
  var doc = DocsList.createFile(fileBlob);
  var app = UiApp.getActiveApplication();

  var fileBlob2 = e.parameter.Reference2;
  var doc = DocsList.createFile(fileBlob2);
  var app = UiApp.getActiveApplication();

  var fileBlob3 = e.parameter.Reference3;
  var doc = DocsList.createFile(fileBlob3);
  var app = UiApp.getActiveApplication();

  //Display a confirmation message
  var label = app.createLabel('Thank You for uploading files').setStyleAttribute('font-weight','bold').setStyleAttribute('font-size','1.1em');
  app.add(label);

  return app;

}

有什么方法可以在框中而不是在标签中显示确认消息吗? 我还必须显示该程序其他部分的确认消息。

谢谢

您可以使用DialogBoxPopupPanel代替label。 有关详细信息,请查看链接的文档。

附带一提,您的doPost()函数代码将var app设置了3次,这是不必要的。 您可能还需要编辑代码,以解决未选中并上传所有3个文件的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM