更新时间:2023-11-27 15:00:34
它正在查找重复项,因为您正在检索几个空单元格,并且两个空字符串彼此都是重复项.
It is finding duplicates because you are retrieving several empty cells, and two empty strings are duplicates from each other.
At readData
, you are providing lastRow
as the third parameter of getRange(row, column, numRows). This refers to the number of rows in your range. Since the first row is 6, the last 6 rows in the retrieved range will be empty cells. You can fix that by making your third parameter var numRows = lastRow - firstRow + 1
instead.
此外,为了确保列中没有空单元格,您可以通过 filter(String)
从数组中将其删除(请参见
Also, in order to make sure you have no empty cells in the column, you can remove them from your array via filter(String)
(see filter).
此外,我建议使用flat()以获得一维数组,而不是您使用的更复杂的 concat
和 apply
过程.
Also, I'd suggest using flat() in order to get a 1D array, instead of the more complicated concat
and apply
process you're using.
function readData() {
var dataColumn = 3;
var firstRow = 6;
var lastRow = ssSheet.getLastRow();
var numRows = lastRow - firstRow + 1;
var columnRange = ssSheet.getRange(firstRow, dataColumn, numRows);
var rangeArray = columnRange.getValues().flat().filter(String);
return rangeArray;
}