【发布时间】: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