【问题标题】:add check box to multi select drop down list in google sheets将复选框添加到谷歌表格中的多选下拉列表
【发布时间】: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


    【解决方案1】:
    function insertCheckboxes(startrow = 2, column = 5) {
      if (startrow && column) {
        const ss = SpreadsheetApp.getActive();
        const sh = ss.getSheetByName("MasterData");
        sh.insertColumnBefore(column)
        sh.getRange(startrow, column, sh.getLastRow() - startrow + 1).insertCheckboxes();
      }
    }
    

    【讨论】:

    • 我无法让它工作。我是菜鸟。我需要指定我希望它从哪里开始吗?function insertCheckboxes(startrow,column) { const ss = SpreadsheetApp.getActive(); const sh = ss.getSheetByName("MasterData"); sh.getRange(2,25,sh.getLastRow() - startrow + 1).insertCheckboxes();我收到关于范围内的行数必须至少为 1 的错误。我还需要将此添加到我的代码中以允许多选吗?我假设我只是不知道我在一次运行多个功能时遇到问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多