我正在研究一个简单的脚本,该脚本旨在复制选项卡并删除其中输入了特定列的信息的行。但是,当满足if()
的条件时,该行不会被删除,我得到“这些行是我们的界限错误”。
这是我的代码:
var sss = SpreadsheetApp.openById('Sheet ID');
var ss = sss.getSheetByName('Purchase History');
var rangeToCopy = ss.getRange('A4:U');
var tss = SpreadsheetApp.openById('Sheet ID');
var ts = tss.getSheetByName('Portfolio');
var tr=ts.getRange("'Portfolio'!A1:U")
var lastRow = ts.getLastRow()
if (lastRow > 3) { // only keep "header"
ts.deleteRows(5,lastRow-4) // can't delete all frozen rows
ts.getRange(4,1).clear() // so just clear the last one
}
rangeToCopy.copyTo(ts.getRange(4,1))
var lastRow = ts.getLastRow() // delete stocks that were sold
for (var i = lastRow; i >= 4; i--) {
var cell = tr.getCell(i,20)
if (cell.isBlank() == false) {
ts.deleteRow(i) // ERROR appears here when the cell is not blank
}
这是我第一次使用表格进行编码,对于任何公然的错误表示歉意