将值添加到单元格下拉列表中

时间:2016-06-15 08:33:23

标签: javascript arrays google-apps-script

我正在尝试使用Google Script从电子表格中向in-cell dropdown list添加一些值,但我无法使其正常运行......

这是我的代码:

  var justRS = rs.report_suites;
  var rsID = [];
  for(var prop in justRS) {
    rsID.push(justRS[prop].rsid);
  }

  var cell = SpreadsheetApp.getSheets()[4].getRange("A1");
  var rule = SpreadsheetApp.newDataValidation().build();
  cell.setDataValidation(rule).setValue(rsID);

细胞" A1"应包含in-cell dropdown list,其值为rsID数组...

1 个答案:

答案 0 :(得分:1)

解决了,这是解决方案:

  var cell = SpreadsheetApp.getActiveSpreadsheet().getSheets()[4].getRange("A1");
  var rule = SpreadsheetApp.newDataValidation().requireValueInList(rsID, true).build();
  cell.setDataValidation(rule);