我使用下面的脚本将数据从工作表(Invoice_Info)移动到(Invoice_Archive) 当单元格值="保存"在第20栏
在工作表中的(Invoice_Archive)我将arrayformula放在第21列
中问题是: - 当数据移动到工作表(Invoice_Archive)时,它放在工作表的末尾
- 当我删除arrayformula时,脚本运行良好
我应该怎么做才能使用arrayformula
来处理脚本提前致谢
function onEdit() {
var sheetNameToWatch1 = "Invoice_Info";
var columnNumberToWatch = 20;
var valueToWatch = "Save";
var sheetNameToMoveTheRowTo = "Invoice_Archive";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
if ( (sheet.getName() == sheetNameToWatch1) && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet.getRange(range.getRow(), 1, 1, 20).copyTo(targetRange, {contentsOnly:true});
sheet.deleteRow(range.getRow());
}
}

答案 0 :(得分:0)
我相信你的问题在于目标表中的getLastRow。 arrayformula导致行错误。尝试使用数据gstting最后一行a a:
function onEdit() {
var sheetNameToWatch1 = "Invoice_Info";
var columnNumberToWatch = 20;
var valueToWatch = "Save";
var sheetNameToMoveTheRowTo = "Invoice_Archive";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
if ( (sheet.getName() == sheetNameToWatch1) && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var Avals= targetSheet.getRange("A1:A").getValues()
var Alast = Avals.filter(String).length;
var targetRange = targetSheet.getRange(Alast + 1, 1);
sheet.getRange(range.getRow(), 1, 1, 20).copyTo(targetRange, {contentsOnly:true});
sheet.deleteRow(range.getRow());
}
}