[英]Confirmation Message Box Using Google Apps Script
我已經實現了Google Apps腳本代碼來顯示確認消息,我成功地使用了標簽顯示了該消息,但是我試圖在一個框中而不是標簽中顯示確認消息,以便用戶可以清楚地看到他們提交了文件成功,可以單擊該框中的“確定”按鈕。 我嘗試使用以下代碼實現此目標,但顯示以下錯誤消息:
“遇到的錯誤:只能從綁定到新版Google表格的腳本中調用SpreadsheetApp.getUi()。”
這是我創建的用於編寫Google Apps腳本代碼的新Google Spreadsheet,但是我復制並粘貼了現有代碼。
這是我嘗試用來顯示確認消息框的代碼(上面顯示了錯誤消息):
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代替label。 有關詳細信息,請查看鏈接的文檔。
附帶一提,您的doPost()函數代碼將var app
設置了3次,這是不必要的。 您可能還需要編輯代碼,以解決未選中並上傳所有3個文件的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.