[英]How to copy data from one spreadsheet to another on edit
I'm trying to program a spreadsheet so that whenever I add a new entry to it, it copies the data from that cell into another spreadsheet. 我正在尝试对电子表格进行编程,以便每当我向其中添加新条目时,它都会将该单元格中的数据复制到另一个电子表格中。 Here's my code (that doesn't seem to work):
这是我的代码(似乎无效):
function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var target = SpreadsheetApp.openById("*************");
var target_sheet = target.getSheetByName("Dashboard");
var last_row = target_sheet.getLastRow();
target_sheet.insertRowAfter(last_row);
var target_range = target_sheet.getRange("A"+(last_row+1)+":G"+(last_row+1));
e.range.copyTo(target_range);
}
Any ideas what I'm doing wrong? 有什么想法我做错了吗?
There are two types of triggers in Apps Scripts - simple triggers and installable triggers. Apps脚本中有两种类型的触发器-简单触发器和可安装触发器。 onEdit() is an example of a simple trigger (the name is implicit).
onEdit()是简单触发器的示例(名称是隐式的)。 And there are limits to what you can do inside a simple trigger.
在简单的触发器中您可以执行的操作受到限制。 And that includes opening another spreadsheet.
包括打开另一个电子表格。
So, coming to the solution. 因此,找到解决方案。 Rename your function to something else, say onEdit1() .
将函数重命名为其他名称,例如onEdit1()。 And set up an installable trigger manually and set it to run each time the spreadsheet is edited.
并手动设置一个可安装的触发器,并将其设置为在每次编辑电子表格时运行。 Hint: Use Resources --> Current project's triggers from the script editor
提示:使用资源->脚本编辑器中当前项目的触发器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.