【发布时间】:2022-01-28 05:04:33
【问题描述】:
我在这里找到了在谷歌表格中创建多选下拉列表的代码,我希望能够在列表中每个项目的前面添加一个复选框,以便用户可以选中或取消选中它以添加将它添加到列表中。
enter image description here
目前使用我的代码,他们无法复制列表中的项目(这很好),但如果他们不小心选择了错误的项目,他们还必须删除单元格的内容并重新开始。
/**
* @OnlyCurrentDoc
*/
function onEdit(e) {
var oldValue;
var newValue;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeCell = ss.getActiveCell();
if (activeCell.getColumn() == 25 && ss.getActiveSheet().getName() == "MasterData") {
newValue = e.value;
oldValue = e.oldValue;
if (!e.value) {
activeCell.setValue("");
}
else {
if (oldValue.indexOf(newValue) < 0) {
activeCell.setValue(oldValue + ',\n' + newValue);
}
else {
activeCell.setValue(oldValue);
}
}
}
}
【问题讨论】:
标签: google-apps-script google-sheets drop-down-menu