如何从 Google Apps 脚本中的列表中获取唯一项目?

罗斯·保罗·阿德里安

我有这个代码片段:

function getTimeFrames(){
  var ss = SpreadsheetApp.getActive();
  var cell = ss.getRange("C1").getValue();
  Logger.log(cell);
  
  var s = ss.getSheetByName(cell).getRange("M2:M");
  var unique = new Set(s.getValues());
  
  unique.forEach(x => Logger.log(x))
}

此代码将从用作 UI 的 Google 表格电子表格中调用,其中 C1 单元格将是用于存储数据的表格的名称。在该表中,我有一个列 (M),我需要从中获取唯一值,以便存储在 UI 表的下拉列表中。

我遇到的问题是我根本无法让唯一值部分起作用。在我的整个实验过程中,我要么得到列 M 的所有值的列表,要么根本没有 Logging 输出。

任何帮助是极大的赞赏!

迈克·斯蒂尔森

尝试

function getTimeFrames(){
  var ss = SpreadsheetApp.getActive();
  var cell = ss.getRange("C1").getValue();
  Logger.log(cell);
  
  var unique = ss.getSheetByName(cell).getRange("M2:M").getValues().flat().filter(onlyUnique)

  console.log(unique)
}
function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Google Apps脚本(JavaScript)中查找列表的唯一项

如何从Google Apps脚本中的urlfetch获取Google搜索结果

如何使用Google SpreadSheet中的唯一项作为Google表单列表项的选择?

如何限制Google Apps脚本中的行数?

如何比较 Google Apps 脚本中的时间

如何获取Google Apps脚本中特定值的检查列?

如何在Google Apps脚本中获取Blob对象的大小?

Google Apps脚本:如何从Blob获取图像?

如何使用Google Apps脚本清除Google表格中的列?

如何在Google Apps脚本中呈现Google Pay按钮

Google Apps脚本-如何依次执行功能?

如何使用 Google Apps 脚本边界数据?

如何在本地调试Google Apps脚本?

如何与同事共享Google Apps脚本?

如何使用Google Apps脚本返回getVisibleValues()?

如何使RegExp工作?(Google Apps脚本)

如何修剪Google Apps脚本输出

如何通过Python使用Google Apps脚本?

从同一项目中的另一个文件运行 Google Apps 脚本

如何获取Google Apps市场通知

如何使用Google Apps脚本在Google表单中获取URL参数?

如何从Google Apps脚本的Google语言代码中获取语言名称?

如何检索包含一个项目的集合中的唯一项目

如何通过Apps脚本在Google表格中“清除格式”

如何按顺序执行Google Apps脚本中的多个功能?

在简单的 Google Apps 脚本中显示错误,如何隐藏

如何使用Google Apps脚本在googlespreadsheet中读取时间?

如何使用Google Apps脚本在Firestore中存储GeoLocation?

如何格式化此 Google Apps 脚本中的时间?