如何插入单元格下拉列表按钮?

时间:2014-02-23 18:06:21

标签: google-apps-script google-sheets

有没有办法通过Apps脚本在电子表格单元格中插入“显示单元格按钮以显示列表”,即使用Data>>Data Validation电子表格菜单插入下拉列表(无需编程) ? 我需要在单元格中显示下拉列表(而不是在Uiapp中)。

3 个答案:

答案 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)

答案 2 :(得分:1)

这是对p0tta问题的回复:

  

这对我有用,但我唯一注意到的是它在视觉上没有显示下拉箭头。你知道怎么做吗?

如果您查看以下规则:

  

requireValueInList(values,showDropdown)

Google的Class DataValidationBuilder

,您会看到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如此简单地回答这个问题。