2014-10-06 49 views
0

我已经实施了Google Apps脚本代码以显示确认消息,我成功地使用标签显示消息,但我试图在框中显示确认消息而不是标签,以便用户很清楚他们已经成功提交了这些文件,并且可以在该文件夹中点击确定按钮。我尝试使用下面的代码实现此目标,但它显示以下错误消息:使用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; 

} 

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

感谢

回答

1

你可以使用DialogBoxPopupPanel,而不是标签。查看链接文档以获取详细信

在附注中,您的doPost()函数代码设置了var app三次,这是不必要的。您可能还想编辑您的代码,以解决未选择和上传所有3个文件的问题。

+0

azawaza,非常感谢您的回答。我按照上面列出的文档中所述应用了PopupPanel。 PopupPanel正在工作,但我确实在popupPanel.setTag('谢谢你的应用程序')中使用了字符串文本。setStyleAttribute('color','blue');但我的文本没有显示在弹出窗口中。任何想法我失踪。您的建议将不胜感激。 – TechPro 2014-10-06 20:09:56

+1

弹出式面板是一个面板,您不能直接在其中写入文本,您应该为其添加一个标签或HTML小部件,然后在其中写入文本。 – 2014-10-06 21:55:50

+0

顺便说一句,标签(在任何UiApp小部件上)实际上是一个不可见的字段,可用于将字符串数据传输到服务器功能。它们通过设计是不可见的。 – 2014-10-06 22:13:27