使用谷歌应用程序脚本的确认消息框
Confirmation Message Box Using Google Apps Script
我已经实现了谷歌应用程序脚本代码来显示确认消息,我成功地使用标签显示了消息,但我试图在一个框中而不是标签中显示确认消息。这样用户就可以清楚地看到他们成功提交了文件,并可以点击该框中的"确定"按钮。我尝试使用下面的代码来实现这个目标,但它显示了以下错误消息:
"遇到错误:SpreadsheetApp.getUi()只能从绑定到新的Google Sheets的版本。"
这是我为编写谷歌应用程序脚本而创建的新谷歌电子表格,但我复制并粘贴了现有的代码。
这是我试图用来显示确认消息框的代码(显示上面列出的错误消息):
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;
}
有没有办法在方框中而不是在标签中显示确认消息?我还必须显示程序其他部分的确认消息。
感谢
您可以使用DialogBox或PopupPanel来代替标签。有关详细信息,请查看链接的文档。
顺便说一句,doPost()函数代码将var app
设置了三次,这是不必要的。你可能还想编辑你的代码,以说明不是所有3个文件都被选择和上传。
相关文章:
- Rails:将表单字段值添加到数据确认消息中
- Javascript-如果用户没有响应,则关闭确认消息
- 如果确认消息,则触发单击事件
- 如何在提交时向Happy.js添加确认消息
- Laravel提交按钮上的确认消息
- 正在尝试在确认消息中显示变量值:Javascript
- 在chrome上显示类似于关闭窗口时的firefox的警报消息.确认消息”;离开"或“;留在这个页面上&quo
- Codeigniter:确认消息Javascript未显示
- Jquery:没有确认消息
- 删除记录确认消息
- 确认消息没有提示
- 插入之前的客户端是/否确认消息
- usercontrol中的javascript确认消息框
- 如何在ActionLink中调用删除前的确认消息,然后调用控制器进行删除
- 如何在选中所有输入复选框和单选组后显示javascript确认消息
- 当 Django 中的确认消息为假时,什么都不做
- confirm.html上的动态确认消息
- 向用户显示多条确认消息的最佳方式
- 如何添加Facebook FB.ui对话框确认消息
- 如果用户不接受JS确认消息,如何检查上一个选定的单选按钮