SpreadsheetApp如何从数组中返回唯一值 [英] SpreadsheetApp how to return unique values from an array
本文介绍了SpreadsheetApp如何从数组中返回唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我做的功能.var myArray
是名称列表.我无法从此数组中获取唯一值并将其设置到另一张纸上.我只想要一次名字.
Here is the function I made. The var myArray
is a list of names. I'm not able to get only unique values from this array and set it to another sheet. I just want the names once.
function array() {
var app = SpreadsheetApp;
var ss = app.getActiveSpreadsheet().getSheetByName("test");
var destinationSheet = app.getActiveSpreadsheet().getSheetByName("test2");
var myArray = ss.getRange(2,1,30).getValues();
destinationSheet.getRange(2, 1, 30).setValues(myArray);
}
有人可以帮我过滤这个数组吗?
Can someone help me to filter this array?
推荐答案
这是另一种方法(适用于Google脚本)
Here's an alternative approach (for Google Script)
function myArray() {
var ss, s, a;
ss = SpreadsheetApp.getActive();
s = ss.getSheetByName("test").getRange(2, 1, 30).getValues();
a = [];
a.push(s[0]);
for (var n = 1; n < s.length; n++) {
if (a.join().indexOf(s[n].join()) == -1) {
a.push(s[n])
};
}
ss.getSheetByName("test2").getRange(2, 1, a.length, a[0].length).setValues(a);
}
这篇关于SpreadsheetApp如何从数组中返回唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文