[英]How do I get the onEdit script to run
I've created a spreadsheet then added some values. 我创建了一个电子表格,然后添加了一些值。 I opened the script editor through the menu and added an onEdit function.
我通过菜单打开了脚本编辑器,并添加了onEdit函数。 I cannot, for the life of me, get that script to do anything when I edit a cell in the sheet.
在我的生命中,我无法在编辑工作表中的单元格时让该脚本执行任何操作。
It will run if I specifically press the "run" button in the editor, but that sort of defeats the purpose. 如果我特别按编辑器中的“运行”按钮,它将运行,但是这样做会破坏目的。 What am I missing?
我想念什么?
in case it matters here is my code 万一这是我的代码
function onBugEdit() {
Browser.msgBox("test");
var sheet = SpreadsheetApp.getActiveSheet();
var rng = sheet.getActiveRange();
var val = rng.getValues();
var col = rng.getColumn();
var row = rng.getRow();
var h_string = '=HYPERLINK("http://example.com?id='+val+'","'+val+'")';
if(col == 4) {
col = "D";
cell = sheet.getRange(col+row);
cell.setFormula(h_string);
}
};
The project trigger is set for the onEdit function but again nothing happens when I edit a cell. 为onEdit函数设置了项目触发器,但是当我编辑单元格时仍然没有任何反应。
Have you tried calling your function onEdit
not onBugEdit
? 您是否尝试过调用
onEdit
而不是onBugEdit
函数?
Also remember that "edit" is registered when you exit the cell after editing it. 还请记住,在编辑单元格后退出单元格时,将注册“ edit”。
your code could be simplified to: 您的代码可以简化为:
function onEdit(e) {
if(e.range.getColumn() == 4) {
makeHyperlink(e)
}
};
function makeHyperlink(e) {
e.range.setFormula('=HYPERLINK("http://example.com?id='+e.value+'","'+e.value+'")');
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.