Onedit setvalues 不复制代码值,只复制用户输入 [英] Onedit setvalues does not copy code values, only user input is copied

查看:37
本文介绍了Onedit setvalues 不复制代码值,只复制用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://docs.google.com/spreadsheets/d/1rGns0DGQbjlEpxTbdy1T_-m2oh7eK8tM9xyDzGqahJo/edit?usp=sharing

所以我有这个代码,幸好我是从互联网上得到的,但我似乎无法让它从我拥有的填充空单元格的代码中复制C"列中的其他值,供参考.

So I have this code that I thankfully got of the internet but I can't seem to get it to copy the other values in column 'C' from a code I have that fills in empty cells, sheet provided for reference.

function ss1OnEdit(e){
  if(e.range.getSheet().getName()!='source_sheet') return;
  SpreadsheetApp.openById("1rGns0DGQbjlEpxTbdy1T_-m2oh7eK8tM9xyDzGqahJo").getSheetByName("target_sheet").getRange(e.range.getA1Notation()).setValue(e.value);
}
//You can run this function all you want it will not create more than one trigger.  But you must run it once to setup the first trigger.
function createSS1OnEditTrigger() {
  var ss=SpreadsheetApp.getActive();
  var trgs=ScriptApp.getProjectTriggers();
  var found=false;
  for(var i=0;i<trgs.length;i++) {
    if(trgs[i].getHandlerFunction()=="ss1OnEdit") {
      return;
    }
  }
  if(!found) {
    ScriptApp.newTrigger("ss1OnEdit").forSpreadsheet(ss.getId()).onEdit().create();
  }
}

此代码仅设置手动输入的值.如果我们可以让它从代码输入中设置单元格值,我将不胜感激.

This code only sets the values that have been entered manually by hand. I would really appreciate if we can have it set cell value from code input.

我已经阅读了一些关于这个和 getdisplayvalue() 的内容,但到目前为止没有任何对我有用.

I have been reading about this for a bit and the getdisplayvalue() but nothing so far worked for me.

谢谢!

推荐答案

我假设您的问题是为什么用户输入会触发触发器,但 Range.setValues() 不会.如果这是正确的,那么它会按照 简单触发器文档onEdit(e) 在用户更改电子表格中的值时运行».因此,用户更改会触发触发器,但脚本更改不会.

I assume that your question is why the user input fires the trigger, but the Range.setValues() doesn't. If that is correct, then it works as written on the simple trigger docs: «onEdit(e) runs when a user changes a value in a spreadsheet». So a user change will fire the trigger, but a script change won't.

这篇关于Onedit setvalues 不复制代码值,只复制用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆