为什么应用脚本的“onEdit”简单触发器不起作用?

huangapple go评论55阅读模式
英文:

Why won't apps-script "onEdit" simple trigger work?

问题

I added this function, but editing any cell won't leave the desired note.
Why?

function onEdit(e) {
  // 在编辑的单元格上设置注释,以指示修改时间。
  const range = e.range;
  range.setNote('最后修改:' + new Date());
}
英文:

I added this function, but editing any cell won't leave the desired note.
Why?

function onEdit(e) {
  // Set a comment on the edited cell to indicate when it was changed.
  const range = e.range;
  range.setNote('Last modified: ' + new Date());
}

答案1

得分: 0

In the first one I added ("引号") and it works according to your requirements, in the second one I made a variant.

function onEdit(e) {
  // Get the edited cell
  const range = e.range;

  // Sets the comment to the current date
  range.setNote("最后修改日期: " + new Date());
}
function onEdit(e) {
  var range = e.range;
  var timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss');
  range.setComment('最后修改日期: ' + timestamp);
}
英文:

In the first one I added (") and it works according to your requirements, in the second one I made a variant.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

function onEdit(e) {
  // Get the edited cell
  const range = e.range;

  // Sets the comment to the current date
  range.setNote(&quot;Last modification: &quot; + new Date());
}

<!-- end snippet -->

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

function onEdit(e) {
  var range = e.range;
  var timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), &#39;yyyy-MM-dd HH:mm:ss&#39;);
  range.setComment(&#39;Last modified: &#39; + timestamp);
}

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月11日 01:58:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定