我正在制作一个Google Apps脚本,要求在弹出框中输入答案。我希望将变量设置为对话框答案。我有询问的代码,我只需要变量设置的代码。
例如
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
if (button == ui.Button.OK) {
// User clicked "OK".
Logger.log(MenuOpen());
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('You must input an Address.');
Logger.log(onOpen());
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You must input an Address.');
Logger.log(onOpen());
}
}
它将要求提供电子邮件地址,但我希望答案存储在变量中。我该怎么做?
答案 0 :(得分:1)
尝试一下:
function findFileInAFolder() {
var response=SpreadsheetApp.getUi().prompt('Find File Name in FolderId', 'Enter FolderId/Filename', SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
if(response.getSelectedButton()==SpreadsheetApp.getUi().Button.OK) {
var rA=response.getResponseText().split('/');//Using a delimiter like this allows you to input two variables with just one prompt.
var files=DriveApp.getFolderById(rA[0]).getFiles();//The First one is a folder Id
Logger.log(files);
while(files.hasNext()){
var file=files.next();
if(file.getName()==rA[1]) {//The second one is a filename
var output=file.getBlob().getDataAsString();
var userInterface=HtmlService.createHtmlOutput(output);//This creates the html for a dialog
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'File Contents');//This creates a dialog to show the file content if is simple text. If you try to read something like a google doc or a spreadsheet then you will probably get a malformed html error.
break;
}
}
}
}
输入提示对话框:
我的输出提示:(您和您的文件的输出将不同)