我试图复制带有" lead"从第8列到另一个具有不同ID的电子表格,我根本没有得到任何结果。这是我迄今为止所做的。我找不到代码的错误。你能帮我找到吗?
function onEdit(event) {
// assumes source data in sheet named Needed
// target sheet of move to named Acquired
// test column with lead is col 8 or H
// target sheet Id is 1nMpOJrq79UZPI3T9ykc415pAHIODg2he5xqi-DY6Wt0
// sheet name of target Id is Sheet1
var ss = SpreadsheetApp.openById("1nMpOJrq79UZPI3T9ykc415pAHIODg2he5xqi-DY6Wt0");
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "List" && r.getColumn() == 8 && r.getValue() == "lead") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet1");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
}
}
答案 0 :(得分:1)
使用range.setValues()而不是copyTo。 请注意,不会复制格式,只会复制值。 我改变了它的范围尺寸与目标范围的尺寸相匹配。
function onEdit(event) {
// assumes source data in sheet named Needed
// target sheet of move to named Acquired
// test column with lead is col 8 or H
// target sheet Id is 1nMpOJrq79UZPI3T9ykc415pAHIODg2he5xqi-DY6Wt0
// sheet name of target Id is Sheet1
var ss = SpreadsheetApp.openById("1nMpOJrq79UZPI3T9ykc415pAHIODg2he5xqi-DY6Wt0");
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "List" && r.getColumn() == 8 && r.getValue() == "lead") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet1");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
target.setValues(s.getRange(row, 1, 1, numColumns).getValues());
}
}