有没有办法通过Apps脚本在电子表格单元格中插入“显示单元格按钮以显示列表”,即使用Data>>Data Validation
电子表格菜单插入下拉列表(无需编程) ?
我需要在单元格中显示下拉列表(而不是在Uiapp中)。
答案 0 :(得分:5)
我认为我的问题的答案就在这里:
// Set the data validation for cell A1 to require "Yes" or "No", with no dropdown menu.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Yes', 'No'], false).build();
cell.setDataValidation(rule);
答案 1 :(得分:3)
您想要查看此处提供的方法 - https://developers.google.com/apps-script/reference/spreadsheet/data-validation-builder
答案 2 :(得分:1)
这是对p0tta问题的回复:
这对我有用,但我唯一注意到的是它在视觉上没有显示下拉箭头。你知道怎么做吗?
如果您查看以下规则:
Google的Class DataValidationBuilderrequireValueInList(values,showDropdown)
,您会看到craftApprentice将其作为true
放入示例代码中。
您需要将其设为// Set the data validation for cell A1 to require "Yes" or "No", with no dropdown menu.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Yes', 'No'], true).build();
cell.setDataValidation(rule);
:
{{1}}
希望这澄清一下! 另外,感谢craftApprentice如此简单地回答这个问题。