如何在(App Script)电子表格输入框中创建下拉列表? [英] How to create a drop down list in (App Script) Spreadsheet Input Box?
问题描述
我创建了 Browser.inputBox
,它只接受单个文本。不过,我需要做一个下拉列表,我可以从列表中选择,而不是自己输入字符串。
以下是我在单击Odoo时(在菜单栏中)>设置中创建的输入框的屏幕截图。
function menu_settings(params){
if(!params){
params = [[url,URL],[dbname,数据库名称],[用户名,用户名],[密码,密码]];
}
for(var i = 0; i< params.length; i ++){
var input = Browser.inputBox(Server Settings,params [i] [1], Browser.Buttons.OK_CANCEL);
if(input ===cancel){
break;
}
else {
ScriptProperties.setProperty(params [i] [0],input);
}
}
}
基本上不是输入文本,而是需要一个包含预定义值的下拉列表。
我正在检查浏览器类,我看到没有这样的下拉列表选项。我看到的大多数解决方案都是使用单元格中输入文本的DataValidation。但我想给我的代码下拉列表和电子表格上的任何内容。我如何实现这一点?我是新手,所以我需要一些建议!
谢谢!
function fncOpenMyDialog(){
//打开一个对话框
var htmlDlg = HtmlService.createHtmlOutputFromFile('HTML_myHtml')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(200)
.setHeight(150);
SpreadsheetApp.getUi()
.showModalDialog(htmlDlg,'Title To Go Here');
};
您需要一个HTML文件。
HTML_myHtml.html
< select name =nameYouWant>
< option value =something>文字< / option>
< option value =anything>下拉选择< / option>
< / select>
< hr />
< ul>
< li>这是一个列表。< / li>
< li>这是第二行。< / li>
< / ul>
< button onmouseup =closeDia()>关闭< /按钮>
< script>
window.closeDia = function(){
google.script.host.close();
};
< / script>
I created Browser.inputBox
which accepts only a single text. However I need to make a drop down list where I can choose from the list instead of typing the string myself.
The following is the screenshot of the inputBox I created on clicking Odoo(in menu bar)>Settings.
Here is the function that is being triggered:
function menu_settings(params) {
if (!params){
params = [["url", "URL"], ["dbname", "Database Name"], ["username", "username"], ["password", "password"]];
}
for (var i = 0; i < params.length; i++){
var input = Browser.inputBox("Server Settings", params[i][1], Browser.Buttons.OK_CANCEL);
if (input === "cancel"){
break;
}
else{
ScriptProperties.setProperty(params[i][0], input);
}
}
}
Basically instead of typing the text, I need a drop list with predefined values.
I was checking the Browser class and I saw there is no such drop down list option. Most solutions that I have seen use DataValidation from texts input in the cells. But I want to give the list for the dropdown in my code and nothing on the spreadsheet. How do I implement this? I'm a newbie at this so I need some advice!
Thanks!
This is the code to open an HTML dialog:
function fncOpenMyDialog() {
//Open a dialog
var htmlDlg = HtmlService.createHtmlOutputFromFile('HTML_myHtml')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(200)
.setHeight(150);
SpreadsheetApp.getUi()
.showModalDialog(htmlDlg, 'A Title Goes Here');
};
You need an HTML file.
HTML_myHtml.html
<select name="nameYouWant">
<option value="something">Text</option>
<option value="anything">Drop Down Selection</option>
</select>
<hr/>
<ul>
<li>This is a list.</li>
<li>This is line two.</li>
</ul>
<button onmouseup="closeDia()">Close</button>
<script>
window.closeDia = function() {
google.script.host.close();
};
</script>
这篇关于如何在(App Script)电子表格输入框中创建下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!