Google apps script 如何将Google应用程序脚本对话框的答案设置为变量?
我正在制作一个谷歌应用程序脚本,在弹出框中询问答案。我希望将一个变量设置为对话框答案。我有询问的代码,我只需要变量设置的代码 比如说,Google apps script 如何将Google应用程序脚本对话框的答案设置为变量?,google-apps-script,Google Apps Script,我正在制作一个谷歌应用程序脚本,在弹出框中询问答案。我希望将一个变量设置为对话框答案。我有询问的代码,我只需要变量设置的代码 比如说, // Process the user's response. var button = result.getSelectedButton(); var text = result.getResponseText(); if (button == ui.Button.OK) { // User clicked "OK". Logge
// 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());
}
}
它会要求一个电子邮件地址,但我希望答案存储在一个变量中。我该怎么做?试试这个:
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;
}
}
}
}
输入提示对话框:
我的输出提示:(您和您的文件的输出将不同)
欢迎光临。这个问题太宽泛了。请按照上的建议添加更多详细信息,如a和对您的搜索/研究工作的简要描述。“未显示努力-->未给出答案”是在处理志愿者基础准备情况(如本网站)时需要记住的一条很好的指导原则。你可以使用互联网——使用它。学习。这是一个很好的指导方针。谢谢在示例代码中,您已经这样做了—您已经将对话框中的响应存储在变量
text
中。可能你的实际问题是“我如何执行输入验证”和“我如何在获得有效输入之前不断提问”——这两个问题在网上都有很好的记录;你需要展示一些研究成果。