且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将重复的数据发送到数组,然后检查该数组是否为空,如果语句不能正常工作,则决定下一步运行什么代码

更新时间:2023-11-27 15:00:34

问题:

它正在查找重复项,因为您正在检索几个空单元格,并且两个空字符串彼此都是重复项.

Issue:

It is finding duplicates because you are retrieving several empty cells, and two empty strings are duplicates from each other.

readData 处,您提供 lastRow 作为

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;
}