简体   繁体   English

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

[英]Confirmation Message Box Using Google Apps Script

I have implemented the Google Apps Script code to show confirmation message, I am successful in showing the message using the Label but I am trying to display confirmation message in a box instead of the label so that it would be clear to user that they submitted the files successfully and can hit the OK button in that box. 我已经实现了Google Apps脚本代码来显示确认消息,我成功地使用了标签显示了该消息,但是我试图在一个框中而不是标签中显示确认消息,以便用户可以清楚地看到他们提交了文件成功,可以单击该框中的“确定”按钮。 I tried achieving this goal using this code below but it shows following error message: 我尝试使用以下代码实现此目标,但显示以下错误消息:

"Error encountered: SpreadsheetApp.getUi() can only be called from a script bound to the new version of Google Sheets." “遇到的错误:只能从绑定到新版Google表格的脚本中调用SpreadsheetApp.getUi()。”

This is the new Google Spreadsheet I have created to code Google Apps Script, but I copied and pasted the existing code. 这是我创建的用于编写Google Apps脚本代码的新Google Spreadsheet,但是我复制并粘贴了现有代码。

This is the code I tried to use to show confirmation message box (which is showing error message as listed above): 这是我尝试用来显示确认消息框的代码(上面显示了错误消息):

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.');
   }

Below is the code that I am successful showing the confirmation message in label: 以下是我成功在标签中显示确认消息的代码:

// 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;

}

Is there any way to show confirmation message in box instead of in label? 有什么方法可以在框中而不是在标签中显示确认消息吗? I have to show confirmation message for other part of the program also. 我还必须显示该程序其他部分的确认消息。

Thanks 谢谢

You could use DialogBox or PopupPanel instead of label. 您可以使用DialogBoxPopupPanel代替label。 Check linked documentation for details. 有关详细信息,请查看链接的文档。

On a side note, your doPost() function code sets var app three times, which is unnecessary. 附带一提,您的doPost()函数代码将var app设置了3次,这是不必要的。 You might also want to edit your code to account for not all 3 files being selected and uploaded. 您可能还需要编辑代码,以解决未选中并上传所有3个文件的问题。

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

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