谷歌表onedit特定单元格 [英] google sheets onedit specific cell
本文介绍了谷歌表onedit特定单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Google工作表中,我希望在编辑要复制的工作表中的特定单元格后将数据从一个工作表复制到另一工作表.我的代码可以满足我的要求,只是仅由特定的单元格触发.谁能告诉我我想念的东西吗?
In google sheets, I'm looking to have data copied from one sheet to another after editing a particular cell in the sheet being copied. I have code that does what I want except for only being trigger by the particular cell. Can anyone tell me what I'm missing?
function OnEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var destination = SpreadsheetApp.openById("1P6gj2UwfRmSMYZ4LBovvqbqy88aluOysPqWWhWbw_VE")
var source_sheet = ss.getSheetByName("Submit");
var destination_sheet = destination.getSheetByName("Point Tracker");
var source_range = source_sheet.getRange("A2:C2");
var editedcell = source_sheet.getRange("C2");
if(editedcell.getValue() !== 0){
var last_row = destination_sheet.getLastRow();
destination_sheet.insertRowAfter(last_row);
var destination_range = destination_sheet.getRange("A"+(last_row+1)+":C"+(last_row+1));
source_range.copyTo(destination_range,{contentsOnly:true});
source_sheet.getRange("C2").setValue("");
}
}
推荐答案
查看是否可行
function onEdit(e) {
if (e.source.getActiveSheet().getName() !== "Submit" ||
e.range.getA1Notation() != 'C2' || typeof e.value == 'object') return;
SpreadsheetApp.openById("1P6gj2UwfRmSMYZ4LBovvqbqy88aluOysPqWWhWbw_VE")
.getSheetByName('Point Tracker')
.appendRow(e.range.offset(0, -2, 1, 3)
.getValues()[0]);
e.range.setValue(null);
}
注意:此脚本使用事件对象.不要通过单击脚本编辑器中的播放"按钮来测试脚本.而是编辑交流电池,看看它是否有效.
Note: this script uses an event object. Don't test the script by clikcing the play button in the script editor. Instead edit the acual cell and see if it works.
这篇关于谷歌表onedit特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文