【问题标题】:Confirmation Message Box Using Google Apps Script使用 Google Apps 脚本的确认消息框
【发布时间】:2014-10-06 13:15:59
【问题描述】:

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

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

这是我为编码 Google Apps 脚本而创建的新 Google 电子表格,但我复制并粘贴了现有代码。

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

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;

}

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

谢谢

【问题讨论】:

    标签: javascript google-apps-script


    【解决方案1】:

    您可以使用DialogBoxPopupPanel 代替标签。详情请查看链接文档。

    附带说明,您的 doPost() 函数代码设置了 var app 三次,这是不必要的。您可能还想编辑您的代码以说明并非所有 3 个文件都被选中和上传。

    【讨论】:

    • azawaza,非常感谢您的回答。我按照您上面列出的文档中的描述应用了 PopupPanel。 PopupPanel 正在工作,但我确实在 popupPanel.setTag('Thank you for your application').setStyleAttribute('color', 'blue'); 中使用了字符串文本但我的文字没有出现在弹出窗口中。知道我错过了什么。您的建议将不胜感激。
    • 弹出面板是一个面板,你不能直接在里面写文字,你应该给它添加一个Label或者一个HTML小部件,然后在里面写你的文字。
    • 顺便说一句,标签(在任何 UiApp 小部件上)实际上是一个不可见的字段,可以用来将字符串数据传输到服务器函数。它们在设计上是不可见的。
    • 感谢 Serge insas,您的建议解决了向 popupPanel 添加文本的问题。我对 popupPanel 使用了这样的标签:popupPanel.add(app.createLabel('Thank you for your application');
    猜你喜欢
    • 2011-02-13
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 2017-01-02
    相关资源
    最近更新 更多