我设置了Google表格以检查指定列中的源表格上的单元格是否收到值,如果是,则将该行复制到目标工作表并从源表格中删除该行。 / p>
如果源表没有变化,则以下代码似乎有效:
function onEdit(event) {
var editedCell;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Job Schedule" && r.getColumn() == 50 && r.getValue() == "X") { //the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job History");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
}
if(r.getValue() == "H") { //the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job Holding");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
} }
...但是当我尝试反转源和目标表时,没有任何反应。我在这里做错了什么?
function onEdit(event) {
var editedCell;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Job Schedule" && r.getColumn() == 50 && r.getValue() == "X") {
//the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job History");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
}
if(r.getValue() == "H") { //the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job Holding");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
}
if(s.getName() == "Job History" && r.getColumn() == 50 && r.getValue() == "R") { //the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job Schedule");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
}
if(s.getName() == "Job Holding" && r.getColumn() == 50 && r.getValue() == "R") { //the number (50=AX) must match the distance for the 'SHIPPING/SHIP' column
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Job Schedule");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, numColumns);
var source = s.getRange(row, 1, 1, numColumns);
var notes = source.getNotes();
source.copyTo((target), {contentsOnly:true});
target.setNotes(notes);
s.deleteRow(row);
}
}
以下是日志所说的内容:
2018-05-29 10:09:30.409 EDT目标范围的坐标是 在纸张的尺寸之外。在onEdit(代码:63)展开所有| 折叠全部{insertId:" qxgz0dg15to7zh" jsonPayload:{
context:{reportLocation:{...}} message:"坐标 目标范围的大小超出了纸张的尺寸。 在onEdit(代码:63)" serviceContext:{service:" AKfycbxhBfEl0hoqtNu87yC2n5H8MpwYDUhojBjI_G9okmTG" } } 标签: {script.googleapis.com/process_id: " EAEA1GOzXOP8tCPAT0uKRL24EjcxsGpBqJFr9-Tq8Z1rNGrlkYLWlWf7JzvIN1u0tLRPxGjJHjquTAEXXw4hn7vCf2T_UloDjcJQFHKHeKh58fJEXGg7gqfHut_j-zFd__MdCWgLRWiiOlNvTEI-f5CYhVstuN4NyZC-ULQ" script.googleapis.com/project_key: " M-4Ir7ZfvYpEjdXYSVA5_ukuLxhikTIQl"
script.googleapis.com/user_key: " APHrgwr1ptfqh8OKASadCsz3luoVac92py5po4eQivhAsyqN3K0IxIAKMJNxdckvOON6dS9sjCXj" } logName: "项目/项目-ID-6367347185723609045 /日志/ script.googleapis.com%2Fconsole_logs" receiveTimestamp:" 2018-05-29T14:09:31.411762110Z"资源:{
标签:{function_name:" onEdit" invocation_type:"自定义 功能" project_id:" project-id-6367347185723609045" } 键入:" app_script_function" }严重性:"错误"时间戳: " 2018-05-29T14:09:30.409Z" }